添加图片:
android:drawableTop/drawableButtom/drawableLeft/drawableRight
//分别对应在文字的上、下、左、右(在xml中使用)
修改图片尺寸:
//方式一:直接使用ImagView修改尺寸,配合xml使用较好
ImageView tv=(ImageView)View.inflate(container.getContext(),R.layout.inflate_toolbar,null);
tv.setCompoundDrawablesWithIntrinsicBounds(0,iconArr[i],0,0);
tv.setImageResource(iconArr[i]);
//方式二:使用drawable修改图像尺寸
Drawable drawable=tv.getResources().getDrawable(iconArr[i]);
drawable.setBounds(0,0,90,90);
tv.setCompoundDrawables(null,drawable,null,null);
参考:
https://blog.csdn.net/molu_chase/article/details/50805222
https://bbs.csdn.net/topics/391029643
https://zhidao.baidu.com/question/84117550.html
https://blog.csdn.net/hhbgk/article/details/8101676
https://www.cnblogs.com/dukc/p/5137194.html
https://blog.csdn.net/jdsjlzx/article/details/13814041
setBound函数
将drawable绘制在canvas内部(100,100,500,500)表示的矩形区内(这个矩形区域的坐标是以canvas左上角为坐标原点的)
参考:https://blog.csdn.net/zhuhai__yizhi/article/details/79481138