Mobile phone property settings (full screen, horizontal and vertical screen)

Source: Internet
Author: User
Full Screen

In the oncreate method of the activityBefore setcontentview (myview) is calledAdd the following code

Requestwindowfeature (window. feature_no_title); // hide the title getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen, windowmanager. layoutparams. flag_fullscreen); // set full screen.
Landscape Screen

Modify the onresume method of the activity according to the following code example:

@ Overrideprotected void onresume () {/*** set to landscape screen */If (getrequestedorientation ()! = Activityinfo. screen_orientation_landscape) {setrequestedorientation (activityinfo. screen_orientation_landscape);} super. onresume ();}

Or add the Android: screenorientation attribute to the activity node in the configuration file (landscape is horizontal and portrait is vertical)

android:launchMode="singleTask" android:screenOrientation="portrait">

Set the screen to screen_orientation_portrait.

//----------------

Changliang

View. setkeepscreenon (true)

When no code is added for processing the screen rotation, rotating the screen will cause the system to close the current activity and re-open it.
If it is just a simple interface adjustment, we can prevent this problem from occurring. The screen is rotated and the elements of the screen are adjusted by ourselves.
First, we need to modify the androidmanifest. xml file:
<Activity Android: Name = ". Magazine">
</Activity>
// Modify it:
<Activity Android: Name = ". Magazine"
Android: configchanges = "orientation | keyboard">
</Activity>
This allows the program to respond to the events that rotate the screen.
Then rewrite the onconfigurationchanged method:
@ Override
Public void onconfigurationchanged (configuration newconfig ){
// Todo auto-generated method stub
Super. onconfigurationchanged (newconfig );
Log. V ("= onconfigurationchanged ");
Processlayout ();
}

//----------------------------

When we use Android for development,The oncreate method is triggered when the activity is switched to the background or the layout is switched from landscape to portrait.

This can be avoided in Android development. We can use androidmanifest. adding the activit element in XML to this attribute Android: configchanges = "orientation | keyboardhidden" can effectively avoid repeated loading of the oncreat method,

The content of androidmanifest. XML is as follows:

<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. Demo"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
<Activity Android: Name = ". demogps"
Android: configchanges = "orientation | keyboardhidden"
Android: Label = "@ string/app_name">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
<Uses-library Android: Name = "com. Google. Android. Maps"/>

</Application>
<Uses-SDK Android: minsdkversion = "7"/>

<Uses-Permission Android: Name = "android. Permission. Internet"> </uses-Permission>
<Uses-Permission Android: Name = "android. Permission. access_coarse_location"> </uses-Permission>
<Uses-Permission Android: Name = "android. Permission. access_fine_location"> </uses-Permission>
 
</Manifest>

At the same time, the onconfigurationchanged (configuration newconfig) method is reloaded in the Java file of the activity, so that methods such as layout switching or window switching are not reloaded. The Code is as follows:

@ Override
Public void onconfigurationchanged (configuration newconfig)
{
Super. onconfigurationchanged (newconfig );
If (this. getresources (). getconfiguration (). Orientation = configuration. orientation_landscape)
{
// Land
}
Else if (this. getresources (). getconfiguration (). Orientation = configuration. orientation_portrait)
{
// Port
}
}

//------------------------------------------------------

You can use the activity in the androidmanifest. xml file to configure the horizontal and vertical screen switching of the activity in Android:

android:screenOrientation=["unspecified" | "user" | "behind" |
"landscape" | "portrait" |
"sensor" | "nonsensor"]

Screenorientation is used to specify the display direction of the activity on the device. Each value indicates the following meaning:

"unspecified" The default value is used by the system to determine the display direction. The rule is related to the device, so different devices have different display directions.
"landscape" Horizontal Screen Display (longer than width)
"portrait" Portrait display (height to width)
"user" User's current preferred direction
"behind" Consistent with the direction of the activity under the activity (in the activity stack)
"sensor" It is determined by a physical sensor. If you rotate the device, the screen will be switched horizontally and vertically.
"nosensor" Ignore the physical sensor so that it will not change as the user rotates the device ("unspecified"Not set ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.