Android五大布局詳解——FrameLayout(幀布局)


FrameLayout

這個布局相對前面兩節介紹的布局就簡單了很多,因此它的應用場景也就特別的少。這種布局沒有方便的定位方式,所有的控件都會默認擺放在布局的左上角。新建UILayoutTestThree工程,修改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:text="This is FrameLayout"
        />

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

</FrameLayout>

運行程序,效果如圖:

可以看到兩個控件都集中在了左上角的位置。因為TextView控件在Button控件之前添加,因此Button在TextView上面。之前我們學習了layout_gravity屬性來指定控件在布局中的對齊方式,這里也同樣適用。修改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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM