The frame layout does not have any positioning, and all controls are placed in the upper-left corner of the layout.
code example:
Framelayout.xml
<?XML version= "1.0" encoding= "Utf-8"?><Framelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/firstview"Android:text= "First Layer"android:textsize= "50SP"Android:textcolor= "#000000"/> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/secondview"Android:text= "Second Layer"android:textsize= "30SP"Android:textcolor= "#ffff00"/> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/thirdview"Android:text= "third tier"android:textsize= "15SP"Android:textcolor= "#ff00ff"/></Framelayout>
The results shown are:
Thus
The elements in the framelayout layout are placed directly in the upper-left corner of the layout.
Let's change the code a little bit.
Framelayout.xml
<?XML version= "1.0" encoding= "Utf-8"?><Framelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/firstview"Android:text= "First Layer"android:textsize= "50SP"Android:textcolor= "#000000"/> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/secondview"Android:text= "Second Layer"android:textsize= "30SP"Android:textcolor= "#ffff00"/> <TextViewAndroid:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:id= "@+id/thirdview"Android:text= "third tier"android:textsize= "15SP"Android:textcolor= "#ff00ff"android:gravity= "Right"/></Framelayout>
At this point the effect is:
Look at the results, it seems to be different from the previous said, the third layer is not in the upper left corner of the layout, in fact, because we put this TextView set width of fill_parent, and gravity for right, in fact, the third layer is still sitting on the upper level, It's not just the elements in this layer that align right.
Is it true that the child elements in the framelayout have absolutely no control over their position in the layout? Not really, the Android:laytou_gravity property can adapt the position of the control in the layout
Look at the code:
Framelayout.xml
<?XML version= "1.0" encoding= "Utf-8"?><Framelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/firstview"Android:text= "First Layer"android:textsize= "50SP"Android:textcolor= "#000000"/> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/secondview"Android:text= "Second Layer"android:textsize= "30SP"Android:textcolor= "#ffff00"/> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/thirdview"Android:text= "third tier"android:textsize= "15SP"Android:textcolor= "#ff00ff"android:layout_gravity= "Right" /></Framelayout>
Results show
The third layer is really on the right side of the layout, so the framelayout layout default All controls are left-aligned. Control can control its position in the parent control through the Android:layout_gravity property .
Android Notes (eight) layout in Android--frame layout