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" />
效果如下图:
灰色部分为自动填充的高度
更多相关文章
- EditText控件设置只读
- Android上鲜为人知的UI控件介绍和使用
- 用shape美化控件
- Android 控件界面转成Bitmap
- unity3d 获取剩余空间大小 android and ios
- android UI控件之webview控件使用实例:加载网页到webview中
- Android - 获取控件(包括状态栏与标题栏)宽高
- android获取控件宽高