[英]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=256dp
和height=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): 如果您不想拉伸图像,可以使用以下选项(也许不是全部):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.