设计过程中,activity有上下固定高度的菜单,需要控件能自动填充中间的空白部分。
发现在一个容器里,其他控件没有android:layout_weight设定时,给linearlayout指定android:layout_weight就能自动填充空余的高度。
省去了很多取屏幕高度的复杂的运算,感觉相当的棒!


    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

            android:id="@+id/portal_welcome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="动态信息(根据数据库内容填充)"
        android:textSize="24sp" />

            android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        android:orientation="vertical" >

                    android:id="@+id/portal_menu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="32sp固定菜单项位置"
            android:textSize="32sp" />

                    android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#22333333"
            android:gravity="top"
            android:orientation="vertical" >

                            android:id="@+id/portal_menu"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="android:layout_weight  填充 " />
       

                    android:id="@+id/portal_menu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="40sp菜单项"
            android:textSize="40sp" />
   

效果如下图:


灰色部分为自动填充的高度


更多相关文章

  1. Android上鲜为人知的UI控件介绍和使用
  2. 用shape美化控件
  3. 22个值得收藏的android开源代码-UI篇
  4. EditText控件设置只读
  5. android layout_weight讲解
  6. Android应用开发——TextView控件属性列表
  7. android的布局属性中padding和margin的区别
  8. android listview每个item定义动画呈现
  9. android日期控件显示

随机推荐

  1. Android简明开发教程二十四:总结及示例代
  2. Android——修改开机画面
  3. Android--Android四大组件(一)(Android(
  4. Android(安卓)ImageView 总结【转载】
  5. android之ExoPlayer探索
  6. Android(安卓)控件使用之SlidingDrawer
  7. Android(安卓)操作SQLite数据库(初步)-在程
  8. Android与H5的交互
  9. Android: EditText设置属性和设置输入规则
  10. Android(安卓)Animation动画实战(二):从屏幕