我知道关于这一点的讨论随处可见,我自己也处理过这些文件夹,但在阅读之后,我最近对如何在可抽出的文件夹中排列图像产生了很大的困惑。-
看看这个xml文件-

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

    <ImageView android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:scaleType="centerInside"
         android:src="@drawable/img2"
         android:padding="20dp" />

<RelativeLayout

让我们考虑两部关于这种横向模式的手机-
Nexus 10-2560像素*1600像素xHDPI
Nexus 5-1920像素*1080像素XXHDPI
在Nexus 10的情况下-图像大小将为1600px(高度)
在Nexus5的情况下,图像大小是1080px
nexus 10所需的图像大小将大于nexus 5所需的大小,但是nexus10将从xhdpi文件夹(较小的图像大小)获取图像,因为它是xhdpi
nexus 5将从xxhdpi文件夹中获取图像。
所以我该怎么解决这个问题。我有很多类似的布局,在其中我面临着类似的问题。

最佳答案

drawable-hdpidrawable-xhdpidrawable-xxhdpi等仅指定dpi维度,所有大小的设备都将从同一文件夹获取资源,只要它们具有相同的dpi规范。要添加屏幕大小维度,您可以将large(对于设备7“及其周围)、xlarge(对于设备10”及其周围)等添加到该维度中。例如,可以使用drawable-xlarge-xhdpi强制nexus 10“从该文件夹获取特定资源。或者你只能拥有drawable-xlarge,这样所有10“设备都将从这个文件夹中提取资源,不管它们的dpi是什么。
基本上,一个catch all是drawable文件夹,您可以使用drawable-*-*-etc中的值逐个覆盖。文件夹。

10-07 19:00
查看更多