11

I set an image to a RadioButton's drawableLeft, but it's to big. I want to set the image's height, width and scaleType in order to let it looks ok, just like in an ImageView:

android:layout_width="30dip"
android:layout_height="30dip"
android:scaleType="fitXY"

But i find there are no attributions for image when it's set in drawableLeft.

Is there any ways to solve this.

Is it possible to handle this in XML ?

L. Swifter
  • 3,179
  • 28
  • 52

2 Answers2

6

I think this should work:

Drawable drawable = context.getResources().getDrawable(id);
drawable.setBounds(0, 0, 30, 30);
radioButton.setCompoundDrawables(drawable, null, null, null);
Chintan Soni
  • 24,761
  • 25
  • 106
  • 174
  • @L.Swifter For that you have to create your own custom view.. [Go to this link](http://developer.android.com/training/custom-views/index.html) – Chintan Soni Dec 17 '15 at 05:06
1

AFAIK, You will not get all the proporties of an ImageView in drawableLeft. You have to use FrameLayout or RelativeLayout with ImageView and RadioButton for this purpose

You can use android:drawablePadding to get padding between the text and the drawable

Bhargav Thanki
  • 4,924
  • 2
  • 37
  • 43