Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.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
Java 如何在设备中将图像设置为适合屏幕的壁纸?_Java_Android_Screen_Android Wallpaper - Fatal编程技术网

Java 如何在设备中将图像设置为适合屏幕的壁纸?

Java 如何在设备中将图像设置为适合屏幕的壁纸?,java,android,screen,android-wallpaper,Java,Android,Screen,Android Wallpaper,我想将应用程序中查看的图像设置为壁纸 尝试这样做时,图像不适合我的设备屏幕,但使用centerCrop可以正确查看图像 这是我的应用程序代码 活动\u main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.

我想将应用程序中查看的图像设置为壁纸

尝试这样做时,图像不适合我的设备屏幕,但使用centerCrop可以正确查看图像

这是我的应用程序代码

活动\u main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
        android:scaleType="centerCrop"
        app:srcCompat="@drawable/image" />

    <Button
        android:id="@+id/button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="@color/transparent"
        android:text="Set Wallpaper"
        android:textColor="#ffffff" />

    </RelativeLayout>
这是应用程序中使用的图像

实时应用程序屏幕

在安卓设备中设置壁纸后

如何将图像设置为XML文件(缩放到centerCrop)中使用的壁纸,以便将其设置为适用于任何android设备的完美壁纸?

使用:

android:background="@drawable/image"
而不是:

app:srcCompat="@drawable/image" 

设置为匹配家长尝试使用该图像,但没有结果我想将该图像设置为我的智能手机背景(壁纸)
app:srcCompat="@drawable/image"