1

我正在为我的 Android 应用程序的 UI 使用一些 .png 图像。我将图像保存在“res/drawable”目录中。我在一些教程中读到,当屏幕分辨率大于 mdpi 时,Android 会自动放大图像。但是当我在大屏幕设备上运行我的应用程序时,图像显示为其原始大小,而不是按比例放大。其余空间为空(黑色)。我在这里做错了什么?如果有帮助,下面是我的布局的 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:theme="@android:style/Theme.Black.NoTitleBar" 
      >

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView1"
        android:clickable="false"
        android:contentDescription="@string/p"

        android:src="@drawable/volbar" />



    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:contentDescription="@string/p"

        android:src="@drawable/head" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="33dp"
        android:layout_marginRight="19dp"
        android:text="@string/press_to_update" />

    <ImageView
        android:id="@+id/imageView9"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView2"
        android:clickable="false"
        android:contentDescription="@string/p"

        android:src="@drawable/frag11"
         />
    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView9"
        android:layout_alignParentLeft="true"
        android:clickable="false"
        android:contentDescription="@string/p"

        android:src="@drawable/base" />

</RelativeLayout>
4

1 回答 1

1

我猜您希望您的图像按比例放大以填充空间。如果是这种情况,您将需要scaledType为您指定ImageView

<ImageView
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:scaleType="cropInside" />

尝试使用ImageView.ScaleType中的不同值以获得您想要的效果。

仅供参考,当您将图像放入时res/drawable,它会根据设备密度进行缩放。例如,如果您的 png 为 200x150,那么它会在 1.5 密度的设备上缩放为 300x225。这种缩放独立于scaleType.

于 2013-04-14T02:06:59.207 回答