Android Notes (eight) layout in Android--frame layout

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.