设计过程中,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" />
   

效果如下图:


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

android:layout_weight让layout自动调整到剩余高度_第1张图片

android:layout_weight让layout自动调整到剩余高度_第2张图片

更多相关文章

  1. EditText控件设置只读
  2. Android上鲜为人知的UI控件介绍和使用
  3. 用shape美化控件
  4. Android 控件界面转成Bitmap
  5. unity3d 获取剩余空间大小 android and ios
  6. android UI控件之webview控件使用实例:加载网页到webview中
  7. Android - 获取控件(包括状态栏与标题栏)宽高
  8. android获取控件宽高

随机推荐

  1. Android中跟Touch事件
  2. [Android(安卓)基础] -- 深入理解 Androi
  3. 转载: Android 实现左侧列表右侧商品详情
  4. Android中使用ViewPager实现图片的切换
  5. android os编译全过程
  6. Android studio -- java.lang.nullpointe
  7. 获取android设备的IP地址
  8. Android添加桌面快捷方式的简单实现
  9. android启动异常,找不到adb
  10. [置顶] Android开发学习之一——Android