zoukankan      html  css  js  c++  java
  • [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

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

  • 相关阅读:
    UML--->用例图梳理
    UML--->活动图梳理
    论懂产品对程序员的重要性
    markdown时序图语法
    bootstrap 设置表格固定宽度 内容换行
    gitlab的本地搭建和部署使用
    layer.load的使用
    git fatal: remote origin already exists. 报错解决
    导出csv xls文件数字会自动变科学计数法的解决方式
    git常用命令
  • 原文地址:https://www.cnblogs.com/wukong1688/p/10660549.html
Copyright © 2011-2022 走看看