Here we will summarize the operations on the mobile phone screen in Android:
1. Get the screen resolution (because when processing the display in Android, you need to go to different la s or display different materials according to the screen resolution)
<Uses-SDK Android: minsdkversion = "8"/> there is a big difference between adding and not adding
// Obtain it through windowmanager
Displaymetrics dm = new displaymetrics ();
Getwindowmanager (). getdefaultdisplay (). getmetrics (DM );
System. Out. println ("heigth:" + DM. heightpixels );
System. Out. println ("width:" + DM. widthpixels );
// Obtain from resources
Displaymetrics DM2 = getresources (). getdisplaymetrics ();
System. Out. println ("heigth1:" + dm2.heightpixels );
System. Out. println ("width1:" + dm2.widthpixels );
// Obtain the default screen resolution
Display display = getwindowmanager (). getdefaultdisplay ();
System. Out. println ("width-display:" + display. getwidth ());
System. Out. println ("heigth-display:" + display. getheight ());
2. Remove the screen title and full screen display
//
Remove title
Requestwindowfeature (window. feature_no_title );
// Set full screen
Getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen,
Windowmanager. layoutparams. flag_fullscreen );
3. Set the screen direction
Configure activity attributes in the manifest. xml file
<Activity
Android: Name = ". animateactivity" Android: Label = "@ string/app_name"
Android: screenorientation = "Landscape"> <! -- Landscape portrait -->
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
It is usually controlled in the oncreate and ondestroy methods in the activity, because when the screen direction changes,
The system restarts the activity. Therefore, you need to save the relevant data before the activity is destroyed to facilitate the next oncreate method.
Reload and update the screen Layout
Public
Void oncreate (bundle savedinstancestate ){
// Force horizontal screen
Setrequestedorientation (activityinfo. screen_orientation_landscape );
// Todo updates the screen Layout
}
Public void ondestroy (){
If (getrequestedorientation () =
Activityinfo. screen_orientation_landscape ){
// Save data
} Else if (getrequestedorientation () =
Activityinfo. screen_orientation_portrait ){
// Save data
}
}