setCompoundDrawablesWithIntrinsicBounds 与 android:drawableRight

9
什么是通过xml设置drawable的区别,例如:
android:drawableRight="@drawable/arrow_right_normal"

通过代码设置drawable,例如:

bt.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, R.drawable.arrow_right_normal);

因为在第一种情况下,一切都像预期的那样工作(按钮文本水平居中,图标位于右侧中间位置)。 而在第二种情况下,图标位于按钮底部/中部,文本位于左上角顶部。

2个回答

17

right 是第三个参数。最后一个是 bottom。

bt.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.arrow_right_normal,0);

这里是关于编程的文档


1
Drawable drawable = ResourcesCompat.getDrawable(
   getResources(),
   R.drawable.visibility_off,
   getTheme()
); 

textView.setCompoundDrawablesWithIntrinsicBounds(null,null,drawable,null);

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