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