Getting Started with Android development (vi) adapting to direction 6.1 screen direction change

Source: Internet
Author: User

A very important feature of modern mobile devices is the direction in which the screen can be rotated. Of course, Android is no exception. Android supports two screen orientations: Portrait (vertical screen) and landscape (horizontal screen). By default, when you change the screen orientation of a handheld device, the current anctivity automatically redraw its contents. This is because the OnCreate () method is triggered when the screen direction is changed.

Description: When changing the device's screen orientation, in fact, your current activity will be destroyed and recreated.

Then, when the views are redrawn, they may be drawn in the previous screen direction (depending on the layout layout selected).

<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> <tabler 
            ow> <textview/> <checkbox android:id= "@+id/chkrememberpassword" Android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:text= "R" 
     Emember Password "       /> </TableRow> <TableRow> <button android:id= "@+id/b Uttonsignin "android:text=" Log in "/> </TableRow> </TableLayout>

Vertical Screen mode:

Horizontal Screen mode:

Note that in Lanscape horizontal screen mode, there are some blank controls on the right side of the screen that you can use. In addition, when the screen orientation is set to landscape, any view below the screen is hidden.

In general, there are two ways to handle those changes when the screen direction changes.

Add anchor points-the easiest way is to put your views "anchored" on the screen for four weeks. When the screen method changes, this view can be naturally "anchored" in the screen for four weeks.

Resize and position-anchoring and centralizing are simple ways to handle changes in the screen direction, and the more advanced approach is to resize and position each view based on the current screen orientation.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

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.