无法使用背景图片,因为背景图片变得模糊

时间:2020-08-18 05:50:48

标签: android android-imageview

我想使用unsplash(jpg 3456 * 5184,3.21mb)中的图像作为我在android项目中的一项活动的背景图像。我在anydpi部分的drawable文件夹中添加了图片。图片正是 与原始图片相同,但是当我在像素3xL模拟器以及真实设备上运行时,它显示的是如此朦胧,以至于 所以无法帮助我... 这是我的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:id="@+id/nonotes"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".empty_activity">


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:background="@drawable/background" />




    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:rotation="-45"
        android:text="Nothing To Show"
        android:textSize="100sp"
        android:textStyle="bold" />


    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:src="@android:drawable/ic_input_add" />

</RelativeLayout>

Studio Preview

Emulator Preview

1 个答案:

答案 0 :(得分:0)

对于复杂的(大)光栅图像,我们仅将其放置在any-dpi文件夹中就无法正确缩放。

official docs说:

anydpi:此限定符与所有屏幕密度匹配,并且优先于其他限定符。这对于矢量可绘制对象很有用。已在API级别21中添加

有两种方式:

  1. 获取矢量可绘制资源。

  2. 在不同的可绘制目录中添加其他图像,这些图像是:

    ldpi用于低密度(ldpi)屏幕(〜120dpi)的资源。

    mdpi用于中等密度(mdpi)屏幕(〜160dpi)的资源。 (这是基准密度。)

    hdpi用于高密度(hdpi)屏幕(〜240dpi)的资源。

    xhdpi用于超高密度(xhdpi)屏幕(〜320dpi)的资源。

    xxhdpi用于超高密度(xxhdpi)屏幕(〜480dpi)的资源。

    xxxhdpi超高密度(xxxhdpi)使用(〜640dpi)的资源。