TextView设置setCompoundDrawables不生效解决,原因是指定drawable的大小,
解决方案:
TextView tvFruit = view.findViewById(R.id.fruit_name);
tvFruit.setText(fruit.getName());
Drawable dra = context.getDrawable(fruit.getImageId()) ;
dra.setBounds(0, 0, dra.getIntrinsicWidth(), dra.getIntrinsicHeight());;
tvFruit.setCompoundDrawables(dra,null,null,null);
setBounds四个参数的意思:
x - 组件的新 x 坐标。
y - 组件的新 y 坐标。
width - 组件的新 width,单位px。
height - 组件的新 heigh,单位px。
TextView设置setCompoundDrawables不生效解决办法
原文:https://www.cnblogs.com/zhenhunfan2/p/13983750.html