設(shè)置控件填滿屏幕

這里記錄一種方法,用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有一個Fragment一個導(dǎo)航欄,想讓fragment充滿除了底部導(dǎo)航欄之外的地方。
看到Fragment設(shè)置了
layout_height="0dp
layout_weight="1"
BottomNavigationBar沒有設(shè)置layout_weight
但是layout_height設(shè)置為一個具體值
對于一個控件寬或者高設(shè)為0 但是定義了layout_weight,其他控件設(shè)置了具體寬或高的值得情況,就會先將設(shè)置具體值得控件擺放好,其他的位置由設(shè)置了layout_weight的控件填滿。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容