0

Simple question here : I am customizing some buttons, placing an icon next to my text via android:drawableLeft or Right, but I can't seem to find how to define the size with accuracy. My image happen to be too big and go out of the shape of my button.

Oh, and while I am at it: android:drawableLeft allows to put an image on the left of the text, but how to decide the distance FROM the text ? In my case, it automatically goes to the extreme left of my button while my text is centered. The result is everything but nice !

Thanks !

Phalanx
  • 1,217
  • 6
  • 25
  • 36

3 Answers3

1

I recommend to start from this topic.

but how to decide the distance FROM the text ?

Here you have an answer:

android:drawablePadding can be used to specify the amount of padding between the image and button text.

Source

Community
  • 1
  • 1
mmBs
  • 8,421
  • 6
  • 38
  • 46
1

i guess this will do the trick

use android:drawablePadding in conjunction with android:paddingLeft and android:paddingRight to force the text and drawable inward towards the center of the button...

karan
  • 8,637
  • 3
  • 41
  • 78
1

If you want to define the accuracy size of the drawable, You should use Java code instead of android:drawableLeft

  Drawable dw = getResources().getDrawable(R.drawable.ic);
  dw.setBounds(0, 0, 100, 100); // set the size of the drawable to 100*100

  button.setCompoundDrawables(dw, null, null, null);

because of

 android:drawableLeft // equals with  setCompoundDrawablesWithIntrinsicBounds

and

 android:drawablePadding // this used to control the padding between the text and drawable
Shuai
  • 342
  • 3
  • 7