setCompoundDrawablesWithIntrinsicBounds vs. android:drawableRight

use*_*415 8 android

通过xml设置drawable有什么区别

android:drawableRight="@drawable/arrow_right_normal"
Run Code Online (Sandbox Code Playgroud)

并通过代码设置drawable

bt.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, R.drawable.arrow_right_normal);
Run Code Online (Sandbox Code Playgroud)

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

Bla*_*elt 12

right是第三个参数.最后一个是底部

bt.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.arrow_right_normal,0);
Run Code Online (Sandbox Code Playgroud)

这里是文档