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

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

  • 相关阅读:
    CEAA自动汇编脚本常用命令
    PIC之拉电流和灌电流
    CHARRANGE 结构
    汇编中的lodsb和stosb、lodsd和stosd指令
    汇编中的STOSB与STOSD指令
    汇编中的CLD指令
    SQL中distinct的用法
    SQL union介绍
    【项目排期】测试排期问题思考
    SQL join的介绍
  • 原文地址:https://www.cnblogs.com/wukong1688/p/10660549.html
Copyright © 2011-2022 走看看