TextView添加drawable的不同方式

31

在设置drawable的方法方面,TextView有什么区别?文档写得很模糊。

1) setCompoundDrawables (Drawable left, Drawable top, Drawable right, Drawable bottom)
2) setCompoundDrawablesRelative (Drawable start, Drawable top, Drawable end, Drawable bottom)
3) setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom)
4) setCompoundDrawablesRelativeWithIntrinsicBounds(Drawable start, Drawable top, Drawable end, Drawable bottom)

提前致谢。

1个回答

58

setCompoundDrawables方法要求你手动调用Drawable对象的setBounds(Rect)方法来设置边距,而setCompoundDrawablesWithIntrinsicBounds方法会自动确定Drawable对象的边界(就像将ImageView设置为wrap_content一样)。

setCompoundDrawablesRelativesetCompoundDrawables相同,但不同之处在于使用“start”和“end”代替“left”和“right”,这对于支持从左到右和从右到左的本地化非常有用(请参见此博客文章获取更多信息)。setCompoundDrawablesRelativeWithIntrinsicBoundssetCompoundDrawablesWithIntrinsicBounds也是如此。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接