You can obtain a wide height in the OnCreate by the following methods
1 //------------------------------------------------Method One2 intw = View.MeasureSpec.makeMeasureSpec (0, View.MeasureSpec.UNSPECIFIED); 3 inth = View.MeasureSpec.makeMeasureSpec (0, View.MeasureSpec.UNSPECIFIED); 4 Imageview.measure (W, h); 5 intHeight =imageview.getmeasuredheight (); 6 intwidth =imageview.getmeasuredwidth (); 7Textview.append ("\ n" +height+ "," +width); 8 9 Ten One A //-----------------------------------------------Method Two -Viewtreeobserver vto =Imageview.getviewtreeobserver (); -Vto.addonpredrawlistener (NewViewtreeobserver.onpredrawlistener () { the Public BooleanOnpredraw () { - intHeight =imageview.getmeasuredheight (); - intwidth =imageview.getmeasuredwidth (); -Textview.append ("\ n" +height+ "," +width); + return true; - } + }); A //-----------------------------------------------Method Three atViewtreeobserver Vto2 =Imageview.getviewtreeobserver (); -Vto2.addongloballayoutlistener (NewOngloballayoutlistener () { - @Override - Public voidongloballayout () { -Imageview.getviewtreeobserver (). Removeglobalonlayoutlistener ( This); -Textview.append ("\ n" +imageview.getheight () + "," +imageview.getwidth ()); in } -});
Android Beginner Tutorial _ Get the width and height of Android controls