Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
图像未按比例放大(Android)_Android_Xml - Fatal编程技术网

图像未按比例放大(Android)

图像未按比例放大(Android),android,xml,Android,Xml,我正在为我的Android应用程序的UI使用一些.png图像。我将图像保存在'res/drawable'目录中。我在一些教程中读到,当屏幕分辨率大于mdpi时,Android会自动放大图像。但当我在大屏幕设备上运行我的应用程序时,图像显示为原始大小,而不是按比例放大。剩余的空间是空的(黑色)。我做错了什么?下面是我的布局的XML(如果有帮助): <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:androi

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

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

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

使用中的不同值进行实验,以获得所需的效果


仅供参考,当您将图像置于
res/drawable
中时,它会根据设备密度进行缩放。例如,如果png为200x150,则在密度为1.5的设备上,它将缩放为300x225。这种缩放与缩放类型无关,我猜您希望图像放大以填充空间。如果是这种情况,则需要为
ImageView
指定
scaledType

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

使用中的不同值进行实验,以获得所需的效果


仅供参考,当您将图像置于
res/drawable
中时,它会根据设备密度进行缩放。例如,如果png为200x150,则在密度为1.5的设备上,它将缩放为300x225。此缩放独立于
缩放类型

是否根据分辨率将图像上载到res文件夹?是的,正确的分辨率已上载到drawable mdpi和hdpi目录。是否根据分辨率将图像上载到res文件夹?是,正确的分辨率已经上传到drawable mdpi和hdpi目录中。好的,我会测试一下。顺便说一句,我的意思是,当屏幕较大时,增大屏幕大小以填充屏幕,当屏幕较小时,减小屏幕大小以填充屏幕。对不起,我来测试一下。顺便说一句,我的意思是,当屏幕较大时,增大屏幕大小以填充屏幕,当屏幕较小时,减小屏幕大小以填充屏幕。对不起,给你的帽子。