Android UI Framelayout (frame layout)
Description: A frame layout creates an empty area (called a frame) for each of the components contained therein, which is superimposed on a layer of layers, somewhat like a layer of overlay stickers, and the components behind it cover the front.
Framelayout has two more special common properties to note:
1 Android:foreground
Corresponding method: Setforeground (drawable)
Description: Set the foreground image for the frame layout, typically adding pressed state to the layout this property is used to specify a drawable type object.
Give me a chestnut:
<framelayout android:foreground= "@drawable/muogu" android:layout_width= "fill_parent" android:layout_height= "fi Ll_parent "> <textview android:layout_width=" wrap_content "android:layout_height=" Wrap_content " Android:width= "320DP" android:height= "320DP" android:layout_gravity= "center" android:background= "# 3399AA "/> <textview android:layout_width=" wrap_content "android:layout_height=" Wrap_content " Android:width= "280DP" android:height= "280DP" android:layout_gravity= "center" android:background= "#A A77aa "/> <textview android:layout_width=" wrap_content "android:layout_height=" Wrap_content " Android:width= "240DP" android:height= "240DP" android:layout_gravity= "center" android:background= "#66 2288 "/> <textview android:layout_width=" wrap_content "android:layout_height=" Wrap_content " Android:width= "200DP" android:height= "200DP" android:layout_gravity= "center" android:background= "#895511"/> <imagev Iew android:layout_width= "160DP" android:layout_height= "160DP" android:layout_gravity= "center" Android:scaletype= "Fitxy" android:src= "@drawable/nailiu16"/></framelayout>
As you can see the picture with the foreground as a small mushroom, the direct stretch of the picture fills the entire framelayout and obscures all the components in the framelayout. This is the effect of the foreground color relative to the background color.
2 foregroundgravity
Corresponding method: setforegroundgravity (int)
Description: Look at the name to know, must be in front of the scenery. Yes, the function of this property is to define the gravity property of the foreground image, so this property must be used in conjunction with foreground. The options are more gravity, and you can find the property sheet in the LinearLayout (linear layout) of my previous Android UI.
Give me a chestnut:
<framelayout android:foreground= "@drawable/muogu" android:layout_width= "Fill_parent" android:foregroundgravity = "Bottom|right" android:layout_height= "fill_parent" > <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:width= "320DP" android:height= "320DP" Android:layout_g ravity= "center" android:background= "#3399AA"/> <textview android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:width= "280DP" android:height= "280DP" android:layout_gr avity= "center" android:background= "#AA77AA"/> <textview android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:width= "240DP" android:height= "240DP" Android:layout_gra vity= "center" android:background= "#662288"/> <textview android:layout_width= "Wrap_content" Android:layout_height= "WRap_content "android:width=" 200DP "android:height=" 200DP "android:layout_gravity=" Center "Android oid:background= "#895511"/> <imageview android:layout_width= "160DP" android:layout_height= "160DP" android:layout_gravity= "center" android:scaletype= "Fitxy" android:src= "@drawable/nailiu16"/></f Ramelayout>
The only difference in the code above is the addition of the following line of code in Framelayout.
android:foregroundGravity="bottom|right"
You can see that the foreground image is restored to its original size and placed in the lower-right corner by setting so that the subcomponents in the Framelayout are displayed.
Attached: Citation statement
"Crazy Android Handout (second edition)" Li Gang "2.2.3 Frame Layout" Electronic industry Press
Android UI Framelayout (frame layout)