Issue
I have two imagebuttons, with dimensions 256x256 dp and scaleType="centerCrop"
.
When I see the preview in AS or when I launch the application on my nexus 5 the images are blurry. The images are of the right dimensions for the respective folders, up to 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>
Solution
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. The xxxhdpi
drawable has width and height 192px
(I assume than 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
).
If you don't want to have stretched images, here are some options for you (maybe not all):
- you need to change the scaleType to centerInside (or without scaleType) - you will get smaller buttons - the images are scaleDowned only if needed
- you need to make the ImageButton smaller - 48x48
- 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)
- 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
Answered By - petin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.