设置控件填满屏幕

这里记录一种方法,用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一个导航栏,想让fragment充满除了底部导航栏之外的地方。
看到Fragment设置了
layout_height="0dp
layout_weight="1"
BottomNavigationBar没有设置layout_weight
但是layout_height设置为一个具体值
对于一个控件宽或者高设为0 但是定义了layout_weight,其他控件设置了具体宽或高的值得情况,就会先将设置具体值得控件摆放好,其他的位置由设置了layout_weight的控件填满。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容