在项目中,经常会遇到文字旁边是图片的UI,使用LinearLayout布局显得非常累赘,且会影响性能,最明智的方法是自定义一个TextView,实现方法如下:
public class TextDrawable extends android.support.v7.widget.AppCompatTextView {
private Drawable drawableLeft;
private Drawable drawableRight;
private Drawable drawableTop;
private int leftWidth;
private int rightWidth;
private int topWidth;
private int leftHeight;
private int rightHeight;
private int topHeight;
private Context mContext;
public TextDrawable(Context context) {
super(context);
this.mContext = context;
init(context, null);
}
public TextDrawable(Context context, AttributeSet attrs) {
super(context, attrs);
this.mContext = context;
init(context, attrs);
}
public TextDrawable(Context context, At