图像没有扩大规模(Android)

时间:2013-04-13 12:14:05

标签: android xml

我正在为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>

1 个答案:

答案 0 :(得分: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无关。