android:layout_weight让layout自动调整到剩余高度
设计过程中,activity有上下固定高度的菜单,需要控件能自动填充中间的空白部分。
发现在一个容器里,其他控件没有android:layout_weight设定时,给linearlayout指定android:layout_weight就能自动填充空余的高度。
省去了很多取屏幕高度的复杂的运算,感觉相当的棒!
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="动态信息(根据数据库内容填充)"
android:textSize="24sp" />
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="32sp固定菜单项位置"
android:textSize="32sp" />
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#22333333"
android:gravity="top"
android:orientation="vertical" >
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="android:layout_weight 填充 " />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="40sp菜单项"
android:textSize="40sp" />
效果如下图:
灰色部分为自动填充的高度
更多相关文章
- Android上鲜为人知的UI控件介绍和使用
- 用shape美化控件
- 22个值得收藏的android开源代码-UI篇
- EditText控件设置只读
- android layout_weight讲解
- Android应用开发——TextView控件属性列表
- android的布局属性中padding和margin的区别
- android listview每个item定义动画呈现
- android日期控件显示