Detailed layout six Android --FrameLayout (frame layout)

FrameLayout

This layout is relatively describes the layout of the previous two on a lot simpler, so it's also a special application scenarios less. This layout is no convenient way of locating all of the default controls will be placed in the upper left corner of the layout. New UILayoutTestThree engineer, modify activity_main.xml code:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is FrameLayout"
        />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="FrameLayout"
        />

</FrameLayout>

Run the program, the effect is shown:

you can see two controls are concentrated in the upper left corner position. Because TextView control is added before the Button control, and therefore the above Button in TextView. Before we learned layout_gravity attribute to specify the alignment of the control in the layout, also apply here. Modify the code in activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:text="This is FrameLayout ........."
        />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:text="FrameLayout"
        />

</FrameLayout>

Guess you like

Origin www.cnblogs.com/AleiCui/p/11832834.html