Android Program Development: (6) Adaptive orientation-Changes in the screen direction of 6.1

Source: Internet
Author: User

A very important feature of modern mobile devices is that they can rotate the screen. Of course, Android is no exception. Android supports two screen orientations: portrait and landscape ). By default, when the screen direction of the handheld device is changed, the current ancti will automatically repaint its content. This is because the onCreate () method is triggered when the screen direction changes.
 
Note: When you change the screen direction of a device, in fact, your current activity will be destroyed and re-created.
 
When views are re-painted, they may be drawn in the direction of the previous screen (depending on the selected layout ).
 
[Html] view plaincopy <TableLayout
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_height = "fill_parent"
Android: layout_width = "fill_parent"
>
<TableRow>
<TextView
Android: text = "User Name :"
Android: width = "120dp"
/>
<EditText
Android: id = "@ + id/txtUserName"
Android: width = "200dp"/>
</TableRow>
<TableRow>
<TextView
Android: text = "Password :"
/>
<EditText
Android: id = "@ + id/txtPassword"
Android: password = "true"
/>
</TableRow>
<TableRow>
<TextView/>
<CheckBox android: id = "@ + id/chkRememberPassword"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "Remember Password"
/>
</TableRow>
<TableRow>
<Button
Android: id = "@ + id/buttonSignIn"
Android: text = "Log In"/>
</TableRow>
</TableLayout>
 
Portrait mode:
 
 

Landscape mode:


Note that in lanscape Landscape mode, some white-space controls can be used on the right of the screen. In addition, when the screen direction is set to landscape, any view at the bottom of the screen will be hidden.
 
Usually, when the screen direction changes, you can use two methods to handle those changes.
 
Add an anchor-the simplest way is to "pin" your views around the screen. When the screen method changes, the view views are naturally "anchored" around the screen.
Re-adjust the size and position-"anchoring" and "Concentration" are simple methods to handle screen direction changes. The more advanced method is based on the current screen direction, re-adjust the size and position of each View.
 
 
From manoel's column

Related Article

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.