這里記錄一種方法,用layout_weight
用縱向的舉例,橫向的是一樣的道理
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/colorAccent">
</FrameLayout>
<com.ashokvarma.bottomnavigation.BottomNavigationBar
android:id="@+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="56dp"
/>
</LinearLayout>
上面LinearLayout有一個(gè)Fragment一個(gè)導(dǎo)航欄,想讓fragment充滿除了底部導(dǎo)航欄之外的地方。
看到Fragment設(shè)置了
layout_height="0dp
layout_weight="1"
BottomNavigationBar沒(méi)有設(shè)置layout_weight
但是layout_height設(shè)置為一個(gè)具體值
對(duì)于一個(gè)控件寬或者高設(shè)為0 但是定義了layout_weight,其他控件設(shè)置了具體寬或高的值得情況,就會(huì)先將設(shè)置具體值得控件擺放好,其他的位置由設(shè)置了layout_weight的控件填滿。