Issue
I have one single image with size 1.2MB and with 2436 * 1539 dimension.
I have added this image in single drawable
folder instead of adding it in different drawable folders(drawable-hdpi, drawable-xdpi, drawable-xxdpi, drawable-xxxdpi)
.
When I run my app in Samsung SM-G7102 device, the image does not get displayed. The devices use xhdpi
images. Also it gets displayed in every other device.
But when I add the image in drawable-xxxhdpi
folder it works for this Samsung SM-G7102 device too.
As we know after adding the image in xxxhdpi
Android runtime down samples it for all dpi devices.
But my question is why adding it in simple drawable
folder doesn't work?
Any help will be appreciated. Thanks in advance.
Following is my .xml code for setting image:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/background_image" />
</android.support.constraint.ConstraintLayout>
Solution
res/drawable/
is a legacy directory that is equivalent to res/drawable-mdpi/
.
Android, therefore, will upscale the image when loading it into an -xhdpi
device. That's a 2x increase per dimension, so your resulting image would be 4872 * 3078. That is ~57MB as an ARGB_8888
image, and you probably ran out of memory.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.