Android中有时需动态设置控件四周的drawble图片,这个时候就需要调用 setCompoundDrawables(left, top, right, bottom),四个参数类型都是drawable
Resources res = getResources();
Drawable img_off = res.getDrawable(R.drawable.dianzan_click);
img_off.setBounds(0, 0, img_off.getMinimumWidth(), img_off.getMinimumHeight());<span style="font-family: Arial, Helvetica, sans-serif;">//必须调用Drawable.setBounds()方法,否则图片不显示</span>
holder.tvTopCount.setCompoundDrawables(img_off, null, null, null); //设置左图标
本文介绍如何在Android中为TextView等控件动态设置四周的Drawable图片,通过使用setCompoundDrawables方法,并强调了调用Drawable.setBounds()的重要性。
4435

被折叠的 条评论
为什么被折叠?



