TextView以不同的方式添加drawable

时间:2014-10-05 16:25:42

标签: android textview android-drawable

设置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 个答案:

答案 0 :(得分:33)

setCompoundDrawables要求您手动调用setBounds(Rect)上的Drawable,而setCompoundDrawablesWithIntrinsicBounds将为您确定Drawable的界限(种类)喜欢将ImageView设置为wrap_content)。

setCompoundDrawablesRelativesetCompoundDrawables完全相同,除了使用“left”和“right”之外,它使用“start”和“end”,如果你想支持左边的那么这很有用从右到右和从右到左的本地化(see this blog post for more info)。同样适用于setCompoundDrawablesRelativeWithIntrinsicBoundssetCompoundDrawablesWithIntrinsicBounds