@Override public void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.main); final imageview imageview = (ImageView) findviewbyid (R.id.imageview); int w = view.measurespec.makemeasurespec (0, View.MeasureSpec.UNSPECIFIED); int h = View.MeasureSpec.makeMeasureSpec (0,view.measurespec.unspecified); Imageview.measure (w, h); int height = Imageview.getmeasuredheight (); int width = Imageview.getmeasuredwidth (); textview.append ("\ n" +height+ "," +width); system.out.println ("Execution completed ..." +system.currenttimemillis ()); }
------------------------------------------------Method One
int w = View.MeasureSpec.makeMeasureSpec (0,view.measurespec.unspecified); int h = View.MeasureSpec.makeMeasureSpec (0,view.measurespec.unspecified); Imageview.measure (W, h); int height =imageview.getmeasuredheight (); int width =imageview.getmeasuredwidth (); Textview.append ("\ n" +height+ "," +width);
-----------------------------------------------method Two (pro-Test available!) Called in the OnStart () method)
Viewtreeobserver vto = Imageview.getviewtreeobserver (); Vto.addonpredrawlistener (New Viewtreeobserver.onpredrawlistener () {public Boolean onpredraw () {int height = Imageview.getmeasuredheight (); int width = imageview.getmeasuredwidth (); Textview.append ("\ n" +height+ "," +width); return true; } });
-----------------------------------------------Method Three
Viewtreeobserver Vto2 = Imageview.getviewtreeobserver (); Vto2.addongloballayoutlistener (New Ongloballayoutlistener () {@Override public void ongloballayout () {i Mageview.getviewtreeobserver (). Removeglobalonlayoutlistener (this); Textview.append ("\ n" +imageview.getheight () + "," +imageview.getwidth ()); } });