Get control height and width in Android OnCreate ()
Try to get control height and width in oncreate () Children's shoes are aware that the getwidth () and GetHeight () method return is 0, specific reasons to see the activity life cycle will understand.
Code on:
Method One:
int w = View.MeasureSpec.makeMeasureSpec (0,view.measurespec.unspecified);
int h = View.MeasureSpec.makeMeasureSpec (0,view.measurespec.unspecified);
Ssidtext.measure (W, h);
int width =ssidtext.getmeasuredwidth ();
int height =ssidtext.getmeasuredheight ();
Method Two:
Viewtreeobserver vto = Ssidtext.getviewtreeobserver ();
Vto.addonpredrawlistener (New Viewtreeobserver.onpredrawlistener () {public
Boolean Onpredraw () {
int height = Ssidtext.getmeasuredheight ();
int width = ssidtext.getmeasuredwidth ();
return true;
}
});
Specifically which one can be based on the needs of their own choice.
Thank you for reading, I hope to help you, thank you for your support for this site!