如何在 drawableLeft 中设置图像的宽度和高度
How to set an image's width and height when it's set in drawableLeft
我将图像设置到 RadioButton 的 drawableLeft,但它太大了。我想设置图像的高度、宽度和 scaleType 以使其看起来不错,就像在 ImageView 中一样:
android:layout_width="30dip"
android:layout_height="30dip"
android:scaleType="fitXY"
但是我发现在drawableLeft中设置图像时没有属性。
有什么办法可以解决吗
是否可以在 XML 中处理此问题?
我认为这应该可行:
Drawable drawable = context.getResources().getDrawable(id);
drawable.setBounds(0, 0, 30, 30);
radioButton.setCompoundDrawables(drawable, null, null, null);
据我所知,您不会获得 drawableLeft
中 ImageView
的所有比例。
为此,您必须将 FrameLayout or RelativeLayout 与 ImageView
和 RadioButton
一起使用
您可以使用 android:drawablePadding
在文本和可绘制对象之间进行填充
我将图像设置到 RadioButton 的 drawableLeft,但它太大了。我想设置图像的高度、宽度和 scaleType 以使其看起来不错,就像在 ImageView 中一样:
android:layout_width="30dip"
android:layout_height="30dip"
android:scaleType="fitXY"
但是我发现在drawableLeft中设置图像时没有属性。
有什么办法可以解决吗
是否可以在 XML 中处理此问题?
我认为这应该可行:
Drawable drawable = context.getResources().getDrawable(id);
drawable.setBounds(0, 0, 30, 30);
radioButton.setCompoundDrawables(drawable, null, null, null);
据我所知,您不会获得 drawableLeft
中 ImageView
的所有比例。
为此,您必须将 FrameLayout or RelativeLayout 与 ImageView
和 RadioButton
一起使用
您可以使用 android:drawablePadding
在文本和可绘制对象之间进行填充