First of all, there is a point to declare that, in fact, in Android, the canvas is the height of the width of the screen is actually high.
As a result, there are many ways to get a high screen width:
1.
Java code
WindowManager WindowManager = Getwindowmanager ();
Display display = Windowmanager.getdefaultdisplay ();
ScreenWidth = Display.getwidth ();
ScreenHeight = Display.getheight ();
2.
Java code
Displaymetrics DM = new displaymetrics ();
this. Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);//this refers to the current activity
ScreenWidth =dm.widthpixels;
ScreenHeight =dm.heightpixels;
Both of these methods are still in the 0 state when the screen is not displayed, that is, after the Setcontentview call is not valid.
3.
It can also be obtained by canvas in OnDraw.
Java Code screenwidth =canvas.getwidth (); ScreenHeight =canvas.getheight ();
And the view of the aspect is what most people think of the canvas of the high-width, in fact, he refers to the taskbar and the status bar, in addition to the high-width, mainly the following methods:
1.
Java code
Viewwidth=this. getwidth ();
viewheight=this. getheight ();
2. Rewrite the view's onsizechanged, the method will be called after OnCreate, OnDraw before the
Java code
protected
voidOnsizechanged (
intW
intH
intOLDW,
intOLDH) {viewheight=h; Viewwidth=w;
Super. onsizechanged (W, H, OLDW, OLDH); }
High and wide width of taskbar, status bar I'm not sure yet, but looking from the Internet:
Reference Frameworks/core/res/values/themes.xml
<item name= "Windowtitlesize" >25dip</item>
Frameworks/core/res/values/dimens.xml
<dimen name= "Status_bar_height" >25dip</dimen>
If you want to get a high width in an activity, it's best to put it in the onsizechanged for more insurance.
The above is a summary of my high-width Android, if there are errors in the place, welcome to discuss the message.
In addition, there are some settings for the screen display:
Set to Untitled
Java code requestwindowfeature (window.feature_no_title);
Set to full-screen mode GetWindow (). setflags
Java code
GetWindow (). SetFlags (Windowmanager.layoutparams.flag_fullscreen,windowmanager.layoutparams.flag_fullscreen);
Set to horizontal screen
Java code
Setrequesteorientation (Activityinfo.screen_orientation_ladscape);
(Transferred from: http://blog.csdn.net/yiyaaixuexi/article/details/6233005)