Chapter 3 UI cornerstone-UI layout (3)
3.2.4 frame layout (FrameLayout)
FrameLayout is the simplest layout in the five la S, also known as layer layout or frame layout. In this layout, the entire interface is treated as a blank standby area. All child elements cannot be placed in the specified position. They are placed in the upper left corner of the area and arranged in layers. The layout cannot control the size and position of the Child control, but the child control can control its size and position. The next child element directly overwrites the previous child element and blocks them in part or whole (unless the last child element is transparent ). This layout is usually used for games or for some gallery programs.
We also give a simple example.
<? Xml version = "1.0" encoding = "UTF-8"?> <FrameLayout Xmlns: android = "http://schemas.android.com/apk/res/android" Android: orientation = "vertical" Android: layout_width = "match_parent" Android: layout_height = "match_parent"> <TextView Android: layout_width = "200dp" Android: layout_height = "200dp" Android: background = "@ android: color/white" Android: gravity = "bottom | center_horizontal" Android: text = "text" Android: textColor = "@ android: color/black"/> <ImageView Android: layout_width = "100dp" Android: layout_height = "100dp" Android: background = "@ drawable/icon"/> \ <Button Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "OK"/> </FrameLayout> |
See Figure 3-6.
Figure 3-6 framelayout framework layout (1)
We can see that these controls are all stacked in the upper left corner, and cover one layer. Next, let's change their location through the layout_gravity attribute.
<? Xml version = "1.0" encoding = "UTF-8"?> <FrameLayout Xmlns: android = "http://schemas.android.com/apk/res/android" Android: orientation = "vertical" Android: layout_width = "match_parent" Android: layout_height = "match_parent"> <TextView Android: layout_width = "200dp" Android: layout_height = "200dp" Android: background = "@ android: color/white" Android: layout_gravity = "right" Android: gravity = "bottom | center_horizontal" Android: text = "text" Android: textColor = "@ android: color/black"/> <ImageView Android: layout_width = "100dp" Android: layout_height = "100dp" Android: layout_gravity = "center_horizontal" Android: background = "@ drawable/icon"/> <Button Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_gravity = "center_horizontal" Android: layout_marginTop = "20dp" Android: text = "OK"/> </FrameLayout> |
The effect is 3-7.
Figure 3-7 framelayout framework layout (2)