Android discussion --- getting the phone screen size
SurfaceView simple example
Go to Android --- UI --- ZoomControls to zoom in and out images
For more information, here is a summary of 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)
Java code
// 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 ());
// 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
Java code
// Remove the title
RequestWindowFeature (Window. FEATURE_NO_TITLE );
// Set full screen
GetWindow (). setFlags (WindowManager. LayoutParams. FLAG_FULLSCREEN,
WindowManager. LayoutParams. FLAG_FULLSCREEN );
// Remove the 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
Xml Code
<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>
<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
Java code
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
}
}