简体   繁体   English

xxhdpi屏幕上使用的最低dpi可绘制

[英]The lowest dpi drawable is being used on a xxhdpi screen

I have two imagebuttons, with dimensions 256x256 dp and scaleType="centerCrop" . 我有两个图像按钮,尺寸为256x256 dp和scaleType="centerCrop" When I see the preview in AS or when I launch the application on my nexus 5 the images are blurry. 当我在AS中看到预览或在nexus 5上启动该应用程序时,图像模糊。 The images are of the right dimensions for the respective folders, up to xxxhdpi(192x192). 图像具有相应文件夹的正确尺寸,最大为xxxhdpi(192x192)。

<LinearLayout
    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:orientation="vertical"
    android:background="@android:color/black">

    <ImageButton
        android:layout_marginTop="48dp"
        android:layout_width="256dp"
        android:layout_height="256dp"
        android:id="@+id/button"
        android:layout_gravity="center_horizontal"
        android:src="@mipmap/button_off"
        android:background="@android:color/black"
        android:scaleType="centerInside"
        />
    <ImageButton
        android:layout_width="256dp"
        android:layout_height="256dp"
        android:id="@+id/second_button"
        android:layout_gravity="center_horizontal"
        android:src="@mipmap/second_off"
        android:background="@android:color/black"
        android:scaleType="centerInside"
        />

</LinearLayout>

Please see this documentation first 请首先参阅此文档

https://developer.android.com/guide/topics/resources/providing-resources.html https://developer.android.com/guide/topics/resources/providing-resources.html

then check your project structure. 然后检查您的项目结构。 It's quite unlikely you got this part wrong and there're low-res resources matching first. 您不太可能弄错这部分,并且首先需要匹配低分辨率资源。

If I understood it right - in your XML layout file you set an ImageButton with width=256dp and height=256dp , and src=drawable/your_drawable. 如果我理解正确-在XML布局文件中,将ImageButton设置为width=256dpheight=256dp ,以及src = drawable / your_drawable。 The xxxhdpi drawable has width and height 192px (I assume than mdpi - 48, hdpi - 72, xhdpi - 96, xxhdpi - 144, xxxhdpi - 192). xxxhdpi可绘制对象的宽度和高度为192px (我假设比mdpi-48,hdpi-72,xhdpi-96,xxhdpi-144,xxxhdpi-192)。

If so, than of course the images are blurred, because you set the ImageButtons width/height in mdpi (in xml to 256dp), but you used 144x144 (nexus 5 is xxhdpi) Drawable stretched (because of the scaleType= centerCrop ). 如果是这样,那么图像当然就模糊了,因为您将ImageButtons宽度/高度设置为in mdpi (在xml中为256dp),但是您使用了144x144 (关联5为xxhdpi)可拉伸拉伸(由于scaleType = centerCrop )。

If you don't want to have stretched images, here are some options for you (maybe not all): 如果您不想拉伸图像,可以使用以下选项(也许不是全部):

  1. you need to change the scaleType to centerInside (or without scaleType) - you will get smaller buttons - the images are scaleDowned only if needed 您需要将scaleType更改为centerInside(或不使用scaleType)-您将获得更小的按钮-仅在需要时才将图像缩小
  2. you need to make the ImageButton smaller - 48x48 您需要将ImageButton缩小-48x48
  3. you need to add bigger drawable resources - your mdpi drawable should be as big as your ImageButton in xml (mdpi - 256x 256, hdpi - 384x384, xhdpi - 512x512, xxhdpi - 768x768, xxxhdpi - 1024x1024) 您需要添加更大的可绘制资源-您的mdpi可绘制资源应与xml中的ImageButton一样大(mdpi-256x 256,hdpi-384x384,xhdpi-512x512,xxhdpi-768x768,xxxhdpi-1024x1024)
  4. you post some layout code (XML) in your question with detailed drawable resources resolution which you used and maybe we can make further investigation in your problem 您在问题中张贴了一些布局代码(XML),并使用了详细的可绘制资源解析,也许我们可以对您的问题进行进一步调查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM