如何将 ImageView 放入 Xamarin.Android 根据设备屏幕尺寸自行调整大小的应用程序?
How to put ImageView in Xamarin.Android App which resizes itself depending on device screen size?
我在 Android Asset Studio 中创建了一个图像,它给了我包含文件夹的 zip 文件:drawable-hdpi、drawable-mdpi、drawable-xhdpi、drawable-xxhdpi、drawable-xxxhdpi、每个文件夹包含不同比例的 png 图像。我将这些文件夹粘贴到我的 android 项目的 Resources/drawable 文件夹中。然后我创建了:
<ImageView
android:src="@android:drawable/ic_ac_unit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView1" />
但是屏幕上没有任何显示。在 google 中有很多示例,但它们似乎适用于 android 和 java,因为当我使用 Xamarin.Android 跟随它们时它不起作用。
所以我认为你的问题是你的ImageView的图像来自Android系统,请尝试以下操作:
<ImageView
android:src="@drawable/ic_ac_unit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView1" />
这应该更正。您可能已经注意到我更改了 android:src。你的价值是:
android:src="@android:drawable/ic_ac_unit"
这是试图从 Android OS 的预定义可绘制对象中获取名称为 "ic_ac_unit" 的可绘制对象,而不是从您的可绘制对象中。这就是我遇到的问题。
另外,由 Android Asset Studio 创建的 "drawable-resolution" 文件夹应直接粘贴到项目的 Resources 文件夹中,而不是 Resource/drawable 文件夹中。
我在 Android Asset Studio 中创建了一个图像,它给了我包含文件夹的 zip 文件:drawable-hdpi、drawable-mdpi、drawable-xhdpi、drawable-xxhdpi、drawable-xxxhdpi、每个文件夹包含不同比例的 png 图像。我将这些文件夹粘贴到我的 android 项目的 Resources/drawable 文件夹中。然后我创建了:
<ImageView
android:src="@android:drawable/ic_ac_unit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView1" />
但是屏幕上没有任何显示。在 google 中有很多示例,但它们似乎适用于 android 和 java,因为当我使用 Xamarin.Android 跟随它们时它不起作用。
所以我认为你的问题是你的ImageView的图像来自Android系统,请尝试以下操作:
<ImageView
android:src="@drawable/ic_ac_unit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView1" />
这应该更正。您可能已经注意到我更改了 android:src。你的价值是:
android:src="@android:drawable/ic_ac_unit"
这是试图从 Android OS 的预定义可绘制对象中获取名称为 "ic_ac_unit" 的可绘制对象,而不是从您的可绘制对象中。这就是我遇到的问题。
另外,由 Android Asset Studio 创建的 "drawable-resolution" 文件夹应直接粘贴到项目的 Resources 文件夹中,而不是 Resource/drawable 文件夹中。