来着 http://www.jianshu.com/p/1a5303258754
- 在RelativeLayout 的左边显示一个图片信息
/**
* 初始化 左边的图片
*/
private void initLeftIcon() {
if (leftIconIV == null) {
leftIconIV = new ImageView(mContext);
}
leftImgParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
leftImgParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
leftImgParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, TRUE); //左边
leftImgParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); //上下居中
if (mLeftIconWidth != 0 && mLeftIconHeight != 0) {
leftImgParams.width = mLeftIconWidth;
leftImgParams.height = mLeftIconHeight;
}
leftIconIV.setScaleType(ImageView.ScaleType.FIT_CENTER);
leftIconIV.setId(R.id.id_leftIcon);
leftIconIV.setLayoutParams(leftImgParams);
if (mLeftDrawable != null) {
leftImgParams.setMargins(mLeftIconMarginLeft, 0, 0, 0); //设置边距
leftIconIV.setImageDrawable(mLeftDrawable);
}
addView(leftIconIV);
}
/**
* 初始化 右边的图片
*/
private void initRightIcon() {
if (rightIconIV == null) {
rightIconIV = new ImageView(mContext);
}
rightImgParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rightImgParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, TRUE); //左边
rightImgParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); //上下居中
rightIconIV.setScaleType(ImageView.ScaleType.FIT_CENTER);
rightIconIV.setId(R.id.id_rightIcon);
rightIconIV.setLayoutParams(rightImgParams);
if (mRightIconWidth != 0 && mRightIconHeight != 0) {
rightImgParams.width = mRightIconWidth;
rightImgParams.height = mRightIconHeight;
}
if (mRightDrawable != null) {
rightImgParams.setMargins(0, 0, mRightIconMarginRight, 0); //设置边距
rightIconIV.setImageDrawable(mLeftDrawable);
}
addView(rightIconIV);
}
- 在左测添加 TextView 并设置它的 textview中的字体、颜色、 最大ems、字体是否加粗、字体的布局方式、textView左右两边的drawable等...
实在不想写了 真的好多...
https://github.com/jenosongjiabin/PopularDemo/tree/master/supertextview
网友评论