<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/custom_pic_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/a" />
<TextView
android:id="@+id/custom_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/custom_pic_iv"
android:layout_marginBottom="5dp"
android:layout_marginLeft="8dp"
android:text="2017" />
<TextView
android:id="@+id/custom_text_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/custom_pic_iv"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:text="题目" />
</RelativeLayout>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="@+id/title_bar_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="@null"
android:minHeight="45dp"
android:minWidth="45dp"
android:textSize="14sp" />
<TextView
android:id="@+id/title_bar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:singleLine="true"
android:textSize="17sp" />
<Button
android:id="@+id/title_bar_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="7dp"
android:background="@null"
android:minHeight="45dp"
android:minWidth="45dp"
android:textSize="14sp" />
</merge>
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<declare-styleable name="CustomPicText">
<attr name="pic_backgroud" format="reference"/>
<attr name="pic_backgroud_width" format="dimension"/>
<attr name="pic_backgroud_height" format="dimension"/>
<attr name="pic_text" format="string"/>
<attr name="pic_text_color" format="color"/>
<attr name="pic_text_size" format="integer"/>
<attr name="pic_date" format="string"/>
<attr name="pic_date_color" format="color"/>
<attr name="pic_date_size" format="integer"/>
</declare-styleable>
</resources>
/**
* Created by Hman on 2017/5/4.
* 为了测试自定义组合控件
*/
public class CustomPicText extends RelativeLayout {
private ImageView customPicIv;
private TextView customDateTv;
private TextView customTextTv;
public CustomPicText(Context context, AttributeSet attrs) {
super(context, attrs);
// 加载layout
View view = LayoutInflater.from(context).inflate(R.layout.custom_pictext,this);
customPicIv = (ImageView) view.findViewById(R.id.custom_pic_iv);
customDateTv = (TextView) view.findViewById(R.id.custom_date_tv);
customTextTv = (TextView) view.findViewById(R.id.custom_text_tv);
// 加载自定义属性配置
TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.CustomPicText);
// 为自定义属性添加特性
if (typedArray != null) {
// 为图片添加特性
int picBackgroud = typedArray.getResourceId(R.styleable.CustomPicText_pic_backgroud, 0);
float picWidth = typedArray.getDimension(R.styleable.CustomPicText_pic_backgroud_width,25);
float picHeight = typedArray.getDimension(R.styleable.CustomPicText_pic_backgroud_height,25);
customPicIv.setBackgroundResource(picBackgroud);
// customPicIv.setMinimumWidth(picWidth);
// 为标题设置属性
String picText = typedArray.getString(R.styleable.CustomPicText_pic_text);
int picTextColor = typedArray.getColor(R.styleable.CustomPicText_pic_text_color,16);
int picTextSize = typedArray.getResourceId(R.styleable.CustomPicText_pic_date_size, 16);
customTextTv.setText(picText);
customTextTv.setTextColor(picTextColor);
customTextTv.setTextSize(picTextSize);
// 为日期设置属性
String picDate = typedArray.getString(R.styleable.CustomPicText_pic_date);
int picDateColor = typedArray.getColor(R.styleable.CustomPicText_pic_date_color, 0);
int picDateSize = typedArray.getResourceId(R.styleable.CustomPicText_pic_date_size, 12);
customDateTv.setText(picDate);
customDateTv.setTextColor(picDateColor);
customDateTv.setTextSize(picDateSize);
typedArray.recycle();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:hman="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.eastsun.widget.CustomPicText
android:id="@+id/first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
hman:pic_backgroud="@mipmap/b"
hman:pic_date="2017/5/6"
hman:pic_date_color="@color/white"
hman:pic_text="第一张图片"
hman:pic_text_color="@color/red"
hman:pic_text_size="18"></com.eastsun.widget.CustomPicText>
</LinearLayout>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有