[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

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

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

时间: 2024-08-08 10:36:40

[Android] Android 让UI控件固定于底部的几种方法的相关文章

android 让一个控件按钮居于底部的几种方法

android 让一个控件按钮居于底部的几种方法1.采用linearlayout布局:android:layout_height="0dp" <!-- 这里不能设置fill_parent -->android:layout_weight="1" <!-- 这里设置layout_weight=1是最关键的,否则底部的LinearLayout无法到底部 -->2. 采用relativelayout布局:android:layout_alignPa

给Repeater控件里添加序号的5种方法

.net是目前非常热门的一种程序编译语言,在.net培训中的众多知识点中,给Repeater控件里添加序号的5种方法是非常重要的一个.下面就由达内的老师为大家介绍一下这方面的内容. Repeater是我们经常用的一个显示数据集的数据控件,经常我们希望在数据前显示数据的序号,那么我们该怎么为Repeater控件添加序号呢?下面编辑为大家介绍几种常用的为Repeater控件添加序号的方法: 方法一:利用Container.ItemIndex属性,代码如下: <Itemtemplate ><%

利用来JS控制页面控件显示和隐藏有两种方法

利用来JS控制页面控件显示和隐藏有两种方法,两种方法分别利用HTML的style中的两个属性,两种方法的不同之处在于控件隐藏后是否还在页面上占空位. 方法一:  1 2 document.getElementById("EleId").style.visibility="hidden"; document.getElementById("EleId").style.visibility="visible"; 利用上述方法实现隐

Android L 新增UI控件:RecyclerView CardView的简单使用

源码下载:https://github.com/qyxxjd/RecyclerViewDemo RecyclerView: RecyclerView用来替代ListView,更好的性能而且更容易使用 该控件是一个可以装载大量的视图集合,并且可以非常效率的进行回收和滚动,当你list中的元素经常动态改变时可以使用RecyclerView控件 标准化了ViewHolder,ListView中convertView是复用的,在RecyclerView中,是把ViewHolder作为缓存的单位了 为每个

QT 窗体控件的透明度设置(三种方法)

整个窗体 当设置QT的窗体(QMainWindow, QDialog)时,直接用 [cpp] view plain copy targetForm->setWindowOpacity() 函数即可实现,效果为窗体及窗体内所有控件都透明化了. 二.自定义页面或控件 当设置一个QWidget(一般自定义页面或控件时用QWidget)时,直接设置其窗体透明度无法实现透明效果,目前找到的方法是将整个QWidget当做图形元素,对该图形元素进行设置透明度效果, [cpp] view plain copy

Android基础——基本UI控件:

两种文本框:EditText,TextView, 两种按钮:Button,ImageButton, 单选按钮/单选按钮组:RadioButton,RadioGroup 复选框:CheckBox <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:a

QT中给各控件增加背景图片的几种方法

1. 给QPushButton 增加背景图片:背景图片可根据Button大小自由缩放. void setButtonBackImage(QPushButton *button,QString image,int sizeW, int sizeH) { //163,163为原始分辨率,这里稍做了调整. QPixmap pixmap(image); QPixmap fitpixmap=pixmap.scaled(163,163).scaled(sizeW, sizeH, Qt::IgnoreAspe

iOS 使用UI控件的外观协议UIAppearance进行设置默认UI控件样式

在iOS开发中,经常会对UINavigationBar的样式进行全局样式.采用的设置方式有两种: 第一种,采用方式如下: [UINavigationBar appearance] 这种是对一类对象的默认全局外观样式设置,它对设置时机有要求. 通常需要在UIWindow的viewlayout之前.错过了时机后,设置是没有效果的. 可以选择在下面方法内设置: - (BOOL)application:(UIApplication *)application didFinishLaunchingWith

UI控件初始化问题:initWithFrame和initWithCoder、aweakFromNib的执行

在iOS学习和程序开发过程中,我们经常会遇到一些自定义UI控件或控制器在初始化时出现问题,尤其在大家刚开始接触时,几种初始化方法的作用以及调用的时机往往容易混淆,这也跟我们对iOS程序设计中,类的创建和实例化的过程了解不透彻有关系.本文用一些小例子来简单梳理一下几者的关系,后面再陆续讨论一些复杂情况的深入对比. 问题: 一.什么时候用initWithFrame,什么时候用aweakFromNib.initWithCoder 二.在初始化时控件自身的frame何时能获得?layoutSubView