android - a LayoutParams constructor overload with size in dip. Why not? -


in android sdk there isn't overload of constructor of viewgroup (and subclasses) possibilities specify width , height in dp (or dip) instead of in pixel. why? have:

viewgroup.layoutparams(int width, int height) 

could idea have:

viewgroup.layoutparams(int dpwidth, int dpheight, int complexunittype.dip)  

where complexunittype enum units of measurement (for e.g)

you can use method complextodimensionpixelsize used in typedvalue class , method accepts value convert pixel , current device metrics, possible implementation :

int width = 300; // value converted displaymetrics metrics = getresources().getdisplaymetrics(); int widthinpx = typedvalue.complextodimensionpixelsize(width, metrics); 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -