很多需求要求图片加文字,可以ImageView和Textview组合写,但是就是得多写一个控件,还有简单的方式是直接在.xml文件写一个TextView控件,android:drawableLeft="@mipmap/icon" 该图片位于文字左边 android:drawableRight="@mipmap/icon" 该图片位于文字右边 android:drawableTop="@mipmap/icon" 该图片位于文字上边 android:drawableBottom="@mipmap/icon" 该图片位于文字上边android:drawablePadding="@dimen/dp_10" 设置图片与文字之间的距离
我们还要求要适配pad,如果这样写,图片在pad上面就会很小,我们需要给图片设置宽高,三种方案解决
1、重新改成ImageView和Textview组合。
可以直接定义ImageView的宽高;
2、继续TextView。
Drawable drawable=getResources().getDrawable(R.mipmap.icon_next);
drawable.setBounds(0,0,(int)getResources().getDimension(R.dimen.dp_10),(int)getResources().getDimension(R.dimen.dp_10));
tvLimitTime.setCompoundDrawables(null,null,drawable,null);
3、布局里改成自定义TextView。