您的位置:首页 > 移动开发 > Android开发

Android TextView setcompounddrawables 图片不显示的问题

2017-05-31 21:12 627 查看
在代码中可以设置Drawable显示在text的左、上、右、下位置,有如下两个方法:

setCompoundDrawables(left, top, right, bottom)
setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)


1、setCompoundDrawables(left, top, right, bottom)

drawable的宽高是按drawable.setBound()设置的宽高,

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use {@code null} if you do not want a Drawable there. The Drawables must already have had {@link Drawable#setBounds} called.

使用之前必须使用Drawable.setBounds设置Drawable的长宽。

2、setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)

drawable的宽高是按drawable固定的宽高,

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use {@code null} if you do not want a Drawable there. The Drawables’ bounds will be set to their intrinsic bounds.

即通过getIntrinsicWidth()与getIntrinsicHeight()获得,

直接使用setCompoundDrawablesWithIntrinsicBounds代替setCompoundDrawables 在Java代码中使用就可以正常显示。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: