【发布时间】:2018-03-11 21:31:32
【问题描述】:
在 Xamarin Android 应用程序中,我有一个 AppCompatRadioButton,其 drawableLeft 属性设置为 @drawable/person_resized:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/MyRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Selection 1"
android:textSize="24dp"
android:drawableLeft="@drawable/person_resized"
android:drawablePadding="5dp" />
</RadioGroup>
drawable/person_resized.xml 是我用来缩小drawable/person.png 图像的图层列表可绘制对象:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/person"
android:width="22dp"
android:height="22dp" />
</layer-list>
当此视图显示在 Android N 模拟器上时,它的行为正常。 但在我的 Android Kitkat(4.4.4) 设备中,图像尺寸不正确。
这是我在 Android N 中得到的:
这是我在 Android Kitkat 中得到的:
这是怎么回事?
我尝试了以下方法来缩小 Android Kitkat 中的 drawableLeft,但它们都不起作用:
-
Using a ScaleDrawable 缩小drawable 而making sure to
SetLevel,这实际上允许调整drawable 的大小但不受控制;无论我提供什么缩放因子,调整后的图像总是相同的更小尺寸Getting the bitmap from the drawable, resize it and create a new Bitmap drawable,但这会使图像消失
Using an inset drawable,与使用图层列表相同,使图像以其原始大小显示
【问题讨论】:
标签: android android-layout xamarin.android android-appcompat