简体   繁体   中英

How to set an image's width and height when it's set in drawableLeft

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 ?

I think this should work:

Drawable drawable = context.getResources().getDrawable(id);
drawable.setBounds(0, 0, 30, 30);
radioButton.setCompoundDrawables(drawable, null, null, null);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM