Android中TextView,Button 等设置 setCompoundDrawables 无效

在实现设置TextView上方显示图片的时候遇到不显示的现象。

代码如下:
tv_crbt_failed.setCompoundDrawables(getResources().getDrawable(R.drawable.icon_remind_new), null, null, null);

API 解释
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use null if you do not want a Drawable there.** The Drawables must already have had setBounds(Rect) called.**
即对 Drawable 进行宽高设置即可

代码如下:
Drawable dra = getResources().getDrawable(R.drawable.icon_remind_new); dra.setBounds(0, 0, dra.getMinimumWidth(), dra.getMinimumHeight()); tv_crbt_failed.setCompoundDrawables(dra, null, null, null);

你可能感兴趣的:(Android中TextView,Button 等设置 setCompoundDrawables 无效)