先上效果图:
我们可以直接在布局中用RelativeLayout将ImageView和TextView包起来。也可以写一个公用的布局,用include标签将布局引入。但是为了减少我们的代码量,使之变得更简单,我们可以写一个自定义控件。如下:
public class TextMoreView extends FrameLayout {
private TextView mTvDesc;
private ImageView mIvMore,mIvImage;
public TextMoreView(Context context,AttributeSet attrs){
super(context,attrs);
LayoutInflater.from(context).inflate(R.layout.text_more_layout, this);
mTvDesc = (TextView) findViewById(R.id.text_more_desc);
mIvMore = (ImageView) findViewById(R.id.iv_more);
mIvImage = (ImageView) findViewById(R.id.iv_more_title);
TypedArray array = context.obtainStyledAttributes(attrs, R.sty