Horizontal and vertical screen switching)

Source: Internet
Author: User
Switching between landscape and Landscape)

Blog type:

  • Android_app
Abstract 1:
During Game Development, some games can only be played on a horizontal screen. Therefore, when mobile phones are erected and placed, the game screen must be kept on a horizontal screen. At the beginning of game development, it is best to determine whether to use a horizontal screen or a vertical screen. if you can tolerate screen conversion, you not only need to make two interface la S, but also the horizontal and vertical screen switching may cause memory overflow, cause program crash. (Document/jackliao)

To do this, you can simply configure it in androidmanifest. xml. Add this line
Force portrait screen: Java code 

  1. Android: screenorientation = "Landscape"

Or in the Code:

Java code  
  1. Setrequestedorientation (activityinfo. screen_orientation_landscape );

Force landscape: Java code 

  1. Android: screenorientation = "portrait"

Or in the Code:

Java code  
  1. Setrequestedorientation (activityinfo. screen_orientation_portrait );

Abstract:
Settings in the XML file:

To achieve this goal, you only need to add an attribute Android: screenorientation when declaring activity in androidmanifest. xml. The attribute value landscape is a fixed horizontal screen and portrait is a fixed vertical screen.

Code:

Setrequestedorientation (activityinfo. screen_orientation_landscape); // force the screen to be landscape

Setrequestedorientation (activityinfo. screen_orientation_portrait); // portrait Screen

============== Extended ==========

When the screen automatically switches, the application in the default state will call oncreate again, which is equivalent to restarting the application once. At the same time, layout may cause problems that cannot be properly adapted due to landscape screens. To solve the Program Restart problem caused by screen rotation and keyboard switching, you also need to add an attribute: Android: configchanges. This property can be understood as a listener that intercepts the screen rotation and keyboard switching events, and prevents the program from restarting and changing to the onconfigurationchanged method. The common attribute values here are: keyboardhidden | orientation.

Abstract 3:
The horizontal screen mode is set for Android. In most cases, the horizontal screen mode can make up for the shortcomings of the vertical screen-small font, small keyboard, and inappropriate image ratio, in the Landscape mode, the system provides a more gorgeous and smoother sensory experience. The options include Android landscape screen, Android Landscape mode, Android landscape screen, Android landscape screen, and Android landscape screen, android sets full screen mode, Android horizontal screen switching, and Android horizontal screen.

Some games only support horizontal screens, so when the mobile phone is erected and placed, the game screen must still be horizontal. For the screen layout, at the beginning of game development, it is best to determine whether to use landscape screen or landscape screen. if you can tolerate screen conversion, you not only need to make two interface la S, but also switch between landscape and landscape screens may cause memory overflow, cause program crash.

Set horizontal screen layout for Android

1. androidmanifest. xml: Java code 

  1. Android: screenorientation = "Landscape"
  2. Android: configchanges = "orientation | keyboardhidden"

Set in code: Java code 

  1. Requestwindowfeature (window. feature_no_title );
  2. Getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen, windowmanager. layoutparams. flag_fullscreen );

2. Set to full screen mode: Java code 

  1. Getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen, windowmanager. layoutparams. flag_fullscreen );

3. Force a horizontal screen: Java code 

  1. Setrequestedorientation (activityinfo. screen_orientation_landscape );

4. Force the Java code to the portrait Screen 

  1. Setrequestedorientation (activityinfo. screen_orientation_portrait );

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.