Issue
I will get 5 different images from server that will be in xxxhdpi
, xxhdpi
, xhdpi
, hdpi
, mdpi
.
The URL will be something like this.
http://www.abctest.com/image-xxxhdpi.jpg
http://www.abctest.com/image-hdpi.jpg
Is there any way i can put these images in drawable folder. So that each device will pickup the image according to its density. I googled but unable to find any way to achieve this.
Or If go to different approach, and get 1 large image from server, then on smaller devices it will create lagging.
Solution
You can check density of the device by this:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int screenDensity = metrics.densityDpi;
and choose image based on the density.
Edited
or you can also do this :
float density = getResources().getDisplayMetrics().density;
// return 0.75 if it's LDPI
// return 1.0 if it's MDPI
// return 1.5 if it's HDPI
// return 2.0 if it's XHDPI
// return 3.0 if it's XXHDPI
// return 4.0 if it's XXXHDPI
Answered By - Chirag Gohil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.