• [Android] Android 让UI控件固定于底部的几种方法


    Android 让UI控件固定于底部的几种方法
    1.采用linearlayout布局:
    android:layout_height="0dp" <!-- 这里不能设置fill_parent -->
    android:layout_weight="1" <!-- 这里设置layout_weight=1是最关键的,否则底部的LinearLayout无法到底部 -->


    2. 采用relativelayout布局:
    android:layout_alignParentBottom="true" <!-- 这里设置layout_alignParentBottom=true是最关键的,这个属性上级必须是RelativeLayout -->

    =====================================

    布局xml代码如下:

    1)采用linearlayout布局

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="0dp"  <!-- 这里不能设置fill_parent -->
            android:layout_weight="1"    <!-- 这里设置layout_weight=1是最关键的,否则底部的LinearLayout无法到底部 -->
            android:orientation="vertical">

        </LinearLayout>

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

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#ff0000"
                android:focusable="false" />
        </LinearLayout>
    </LinearLayout>

    2)采用relativelayout布局

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"      <!--上级必须是RelativeLayout-->
            android:orientation="vertical">

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#ff0000"
                android:focusable="false"
                android:text="button"/>
        </LinearLayout>
    </RelativeLayout>

    本博客地址: wukong1688

    本文原文地址:https://www.cnblogs.com/wukong1688/p/10660549.html

    转载请著名出处!谢谢~~

  • 相关阅读:
    显示图案
    圆的面积和周长
    Python基础--list列表删除元素
    Python基础--列表添加元素
    Python基础--列表创建访问删除
    Python基础--序列简介
    一个网页通用的测试用例(转载)
    测试计划与测试方案的区别
    判断一棵树是否是二叉平衡树
    判断丑数与寻找丑数
  • 原文地址:https://www.cnblogs.com/wukong1688/p/10660549.html
Copyright © 2020-2023  润新知