java - How to get width and height of resized custom view , before it is drawn -


in custom view .xml , have defined width , height w = 600dp , h = 700dp. know getmeasuredheight() / getmeasuredwidth() give values of width , height after view drawn , may differ i've given in .xml file , there workaround getmeasuredheight() , getmeasuredwidth() values before view drawn on layout, without use of onmeasure() ?

and how calculate changed dp sizes in different screens ? 600h*700w when run on emulator converts 300*300 .

you can override onsizechanged() height , width of view when drawn.refer below:

  @override protected void onsizechanged(int w, int h, int oldw, int oldh) {     mwidth = w;     mheight = h;     super.onsizechanged(w, h, oldw, oldh);     log.d(tag, "onsizechanged: " + " width: " + w + " height: " + h + " oldw " + oldw + " oldh " + oldh); } 

to convert dp pixels can use following code:

   sizeinpixels = (int) typedvalue.applydimension(typedvalue.complex_unit_dip,             sizeindp, getresources().getdisplaymetrics()); 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -