TextView,Button 等设置 setCompoundDrawables 无效

来源:互联网 发布:源码搭建网站 编辑:程序博客网 时间:2024/05/01 17:34


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

mainTv.setCompoundDrawables(null, getResources().getDrawable(R.mipmap.home_press), 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.mipmap.home_press);            dra.setBounds(0, 0, dra.getMinimumWidth(), dra.getMinimumHeight());            mainTv.setCompoundDrawables(null, dra, null, null);


0 0
原创粉丝点击