LinearLayout Example
Let’s look at an example () that shows LinearLayout properties set both in the XML layout file and at runtime.
"
Note that we have a wrapping two sets. is a subclass of , so our example demonstrates nested boxes as if they were all containers.
The top sets up a row () of widgets. The has of padding on all sides, separating it from the other . The width and height are both set to , so the radio buttons will take up only the space that they need.
The bottom is a column () of three widgets. Again, we have of padding on all sides and a “natural” height (). However, we have set to be , meaning the column of radio buttons “claims” the entire width of the screen.
To adjust these settings at runtime based on user input, we need some Java code:
Package
Import
Import
Import
Import
Import
Import
Import
Public class extends
Implements
Public onCreate
Super onCreate
SetContentView
FindViewById
SetOnCheckedChangeListener this
FindViewById
SetOnCheckedChangeListener this
Public onCheckedChanged
If
If
SetOrientation
Else
SetOrientation
Else if
If
SetGravity
Else if
SetGravity
Else if
Дата добавления: 2015-05-16; просмотров: 693;