设计过程中,activity有上下固定高度的菜单,需要控件能自动填充中间的空白部分。
发现在一个容器里,其他控件没有android:layout_weight设定时,给linearlayout指定android:layout_weight就能自动填充空余的高度。
省去了很多取屏幕高度的复杂的运算,感觉相当的棒!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/portal_welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="动态信息(根据数据库内容填充)"
android:textSize="24sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
在Android开发中,通过设置layout_weight属性,可以轻松实现当有上下固定高度的菜单时,中间控件自动填充剩余空间,避免了复杂的屏幕高度计算。这种方式在布局设计中非常实用。
订阅专栏 解锁全文
4178

被折叠的 条评论
为什么被折叠?



