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

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

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

html - jQuery UI Sortable - Remove placeholder after item is dropped -