代码之家  ›  专栏  ›  技术社区  ›  Profile2ForStack

如何在Xamarin中放置ImageView。根据设备屏幕大小自行调整大小的Android应用程序?

  •  1
  • Profile2ForStack  · 技术社区  · 7 年前

    我在Android Asset Studio中创建了一个图像,它给了我一个包含文件夹的zip文件:可绘制hdpi、可绘制mdpi、可绘制xhdpi、可绘制xxhdpi、可绘制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" />
    

    但屏幕上没有显示任何内容。在谷歌有很多例子,但它们似乎是针对android和java的,因为当我使用Xamarin跟踪它们时。Android它不工作了。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Gustavo Gomes    7 年前

    因此,我认为您的问题是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\U ac\U unit”

    这是试图从Android操作系统预定义的可绘制文件中获取名为“ic\U ac\U unit”的可绘制文件,而不是从您的可绘制文件中获取。这就是我看到的问题。

    此外,Android Asset Studio创建的“drawable resolution”文件夹应直接粘贴在项目的Resources文件夹中,而不是粘贴在Resource/drawable文件夹中。