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
Post a Comment