Home » Android » setCompoundDrawablesWithIntrinsicBounds vs. android:drawableRight

setCompoundDrawablesWithIntrinsicBounds vs. android:drawableRight

Posted by: admin June 15, 2020 Leave a comment

Questions:

What is the difference between setting a drawable via xml like

android:drawableRight="@drawable/arrow_right_normal"

and setting a drawable via code like

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

Because in the first case everything works like expected (Buttontext is center horizantal and the icon is in the middle of the right side).
And in the second case the icon is at the bottom/middle of the Button and the Text is at the top left side.

How to&Answers:

right is the third parameter. The last one is bottom

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

Here the documentation