android - Get drawable for different screen density at runtime -


i want print sizes of drawables @ run-time. if on hdpi device can print size of hdpi drawables how access to, lets mdpi , xhdpi well? can access drawables resource ids following code:

final class<r.drawable> c = r.drawable.class; final field[] fields = c.getdeclaredfields();  (int = 0, max = fields.length; < max; i++) {     final int resourceid;     try {         resourceid = fields[i].getint(drawableresources);     } catch (exception e) {         continue;     }     /* make use of resourceid accessing drawables here */ } 

ok found it, explicitly ask particular density drawable this:

drawable drawable = resources.getdrawablefordensity(id, displaymetrics.density_xhigh); 

or preferably version

drawable drawable = resources.getdrawablefordensity(id, displaymetrics.density_xhigh, theme); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -