Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/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 - Fatal编程技术网

我应该为Android中的不同设备创建多少大小的背景图像?

我应该为Android中的不同设备创建多少大小的背景图像?,android,Android,在这里,我有一个320X480图像(照片),并想把它作为我的背景图像在应用程序中 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"

在这里,我有一个320X480图像(照片),并想把它作为我的背景图像在应用程序中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@drawable/background">    

</RelativeLayout>

但是,当我将它放在不同的设备中时,图像会变得非常奇怪(我不知道它是否奇怪,因为它是否重新调整了图像的大小)。
那么,如何解决这个问题呢??

因为有一张照片,照片里只有一个人。如果一个人在设备A中看起来很瘦,但在设备B中看起来很胖,这会让人感到非常奇怪。

有很多方法可以为全屏创建背景。我推荐的3种解决方案如下:

一个图像作为背景解决方案是最常用的解决方案。要实现这一点,您必须为每个主要屏幕大小制作一个图像=ldpi、mdpi、hdpi和xhdpi,并制作:

  • 在布局中居中,使用与居中图像或图形混合的纯色背景色
  • 使其成为一个9面片图像,以适当的方式拉伸
  • 第三种解决方案是创建平铺布局,在其中使用一个图像,然后以平铺方式将其复制到整个屏幕上
  • 在某些情况下,一个可能有效的方法是使用一个图像,然后根据屏幕大小将其剪切掉。这可能会起作用,但如果图像太大,则在小型/老式手机上会出现内存不足异常,因此,对于ldpi、mdpi、hdpi和xhdpi,同样有一个图像
  • 示例(1):

    
    
    飞溅图像可以有任何大小,重要的是图像的外部部分混合到背景色中,这可以通过使具有背景色的图像慢慢混合到与背景相同的颜色中来实现

    (4)的一个例子:

    
    
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@android:color/black">
        <FrameLayout
            android:background="@drawable/splash"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            >
        </FrameLayout>
    </RelativeLayout>
    
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@android:color/black">
        <ImageView
            android:background="@drawable/splash"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            >
        </ImageView>
    </RelativeLayout>