android线性布局设置控件固定在底部,Android UI组件LinearLayout线性布局详解
LinearLayout 线性布局,该布局的继承关系:
1. 什么是线性布局
通俗的说感觉起来和线有关,参照线的特点,有么是横向的,要么是竖向的。
LinearLayout是线性布局控件,它包含的子控件将以横向或竖向的方式排列(通过android:orientation属性来控制),按照相对位置来排列所有的widgets或者其他的containers,超过边界时,某些控件将缺失或消失
2. 线性布局常用基本属性- android:id
- android:orientation
- android:layout_height
- android:layout_width
- android:gravity
- android:layout_gravity
- android:background
- android:layout_margin:
- android:padding
- android:weightSum
- android:layout_weight
- android:baselineAligned
3. 常用属性值介绍:
android:id:这是布局的唯一标识ID
android:orientation:他表示的是这个线性布局是采用横向还是纵向布局,通常来说只有两个值:
1. android:orientation=”vertical”表示采用纵向的布局方式,所有在当前布局中添加的所有控件都依次按竖向排列
2. android:orientation=”horizontal”表示采用横向的布局方式,所有在当前布局中添加的所有控件都依次按横向排列(默认水平)
android:layout_height:表示当前线性布局的高度
4. android:layout_height="match_parent" (表示高度占满整个屏幕)
5. android:layout_height="wrap_content" (表示高度根据其包含的控件自适应调整)
6. android:layout_height="30dp"(自定义设置高度,通常单位为dp)
android:layout_width:表示当前线性布局的宽度
7. android:layout_width="match_parent" (表示宽度占满整个屏幕)
8. android:layout_width="wrap_content" (表示宽度根据其包含的控件自适应调整)
9. android:layout_width="30dp"(自定义设置宽度,通常单位为dp)
android:gravity:表示所有包含在当前布局中的所有控件采用某种方式对齐(默认左对齐)
从上依次往下为:
center (垂直且水平居中)
center_horizontal (水平居中)
bottom (底部对齐)
center_vertical (垂直居中)
clip_horizontal (水平方向裁剪,当对象边缘超出容器的时候,将上下边缘超出的部分剪切掉,剪切基于纵向对齐设置:顶部对齐时,剪切底部;底部对齐时剪切顶部;除此之外剪切顶部和底部.)
clip_vertical (垂直方向裁剪,当对象边缘超出容器的时候,将左右边缘超出的部分剪切掉,剪切基于横向对齐设置:左对齐时,剪切右边部分;右对齐时剪切左边部分;除此之外剪切左边和右边部分.)
end (放在容器的结束位置,不改变其大小)
fill (必要的时候增加对象的横纵向大小,以完全充满其容器)
fill_horizontal (必要的时候增加对象的横向大小,以完全充满其容器. 水平方向充)
fill_vertical (必要的时候增加对象的纵向大小,以完全充满其容器. 垂直方向填充)
left (将对象放在其容器的左部,不改变其大小)
right (将对象放在其容器的右部,不改变其大小)
start (将对象放在其容器的开始位置,不改变其大小)
top (将对象放在其容器的顶部,不改变其大小)
android:layout_gravity:表示当前线性布局相对于父元素的对齐方式
如上所示
android:background:表示当前线性布局的背景颜色
android:margin:表示外边距,通常表示本控件与父控件四面之间的距离
从上往下:
1. 底边距
2. 与控件结尾的边距
3. 左边距
4. 右边距
5. 与控件的起始边距
6. 顶边距
android:padding:表示内边距,通常表示是本元素所有子元素的与父元素边缘的距离,设置在父元素上,比如文字与文本控件的所有距离
从上往下如上所示
android:weightSum:权重的总比例
android:layout_weight:子元素对未占用空间水平或垂直分布的权重
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.qianfeng.demo1.MainActivity"
android:weightSum="6" //总的权重为6
android:orientation="vertical"
>
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"//此控件占用比例为2,其他控件全部占用1,超过比例的权重都不会分配对应的大小,相当于大小为0
android:textSize="30sp"
android:text="aaaa"
android:background="#f00"
p
/>
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="30sp"
android:text="bbbb"
android:background="#0f0"
/>
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="30sp"
android:background="#00f"
android:text="cccc"
/>
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="30sp"
android:text="dddd"
android:background="#0ff"
/>
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="30sp"
android:background="#f0f"
android:text="eeee"
/>
效果图如下:
android:baselineAligned:该控件只对能显示text的子控件有效。
这必须是一个布尔值,要么“true”或“false”,并防止布局调整其子的基线。默认是true
这里介绍一个小细节:
这里以垂直分配权重为列,权重是可以为负数的,权重是根据比例分配对应大小,这里aaaa控件的高为0dp,bbbb控件的高为0dp,所以,aaaa控件分配权重的是5,bbbb分配权重的是1,所以这里aaaa会比bbbb占用比例大。
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.qianfeng.demo1.MainActivity"
android:weightSum="6"
android:orientation="vertical"
>
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:textSize="30sp"
android:text="aaaa"
android:background="#f00"
/>
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="30sp"
android:text="bbbb"
android:background="#0f0"
/>
效果图:
反之,如果设置了aaaa控件的高为match_parent, bbbb控件的高也为match_parent,aaaa控件分配权重的是5,bbbb分配权重的是1,这样就形成了一种想反的效果,相当于aaaa控件分配的是-5 bbbb控件分配的是-1 而-1 比 -5大,所以,对应bbbb控件占用的比例比aaaa大
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.qianfeng.demo1.MainActivity"
android:weightSum="6"
android:orientation="vertical"
>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="5"
android:textSize="30sp"
android:text="aaaa"
android:background="#f00"
/>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="30sp"
android:text="bbbb"
android:background="#0f0"
/>
效果图如下:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
android线性布局设置控件固定在底部,Android UI组件LinearLayout线性布局详解相关推荐
- android线程改变布局,Android线程中设置控件的值提示报错的解决方法
本文实例讲述了Android线程中设置控件的值提示报错的解决方法.分享给大家供大家参考,具体如下: 在Android线程中设置控件的值一般会与Handler联合使用,如下: package com.y ...
- Android 动态创建控件并设置控件的大小之Android屏幕适配攻略(五)
Android 屏幕适配攻略(五)动态创建控件并设置控件的大小 题记 -- 执剑天涯,从你的点滴积累开始,所及之处,必精益求精,即是折腾每一天. 重要消息 flutter中网络请求dio使用分析 视频 ...
- android 除了webview 浏览器控件,AgentWeb是基于Android WebView一个功能完善小型浏览器库...
[技巧沙龙]AI开辟者拭魅战营-7分钟打造1个定制技能.7月22号,我们等你一路! Android 端 AgentWeb 介绍 AgentWeb是一个高度封装的 Android WebView ,简单 ...
- android安卓动态设置控件宽高
LayoutParams layoutParams=p_w_picpathView.getLayoutParams(); layoutParams.width=100; layoutParams.he ...
- android 携程日历控件,仿携程酒店日历组件for小程序
仿携程酒店日历 接受日历组件开发之前,本来是拒绝的,日历组件,表单组件绝逼是前端开发的一个噩梦,尤其要做好一个旅游项目的日历,产品的收货标准只有一条,你看携程都实现了哦, MMP的.要在小程序中实现携 ...
- Android中的基础控件TextView、Button、ImageView、EditText、ProgressBar
文章目录 1 Android中的基础控件 1.1 控件的通用属性 2 TextView 2.1 TextView的继承关系 2.2 TextView的常用属性 3 EditText 3.1 常用属性 ...
- 07.移动先行之谁主沉浮----控件之轮流轰炸——布局类控件
如果移动方向有任何问题请参考===> 异常处理汇总-移动系列(点) 移动先行之谁主沉浮? 带着你的Net飞奔吧! 链接======>(点) 一.布局类控件 Grid.StackPanel. ...
- 【React Native开发】React Native控件之DrawerLayoutAndroid抽屉导航切换组件解说(13)
转载请标明出处: http://blog.csdn.net/developer_jiangqq/article/details/50599951 本文出自:[江清清的博客] (一)前言 [好消息]个人 ...
- Android 开发 -- 开发第一个安卓程序、Android UI开发(布局的创建:相对布局和线性布局、控件单位:px pt dp sp、常用控件 、常见对话框、ListView)
文章目录 1. 开发第一个Hello World程序 1.1 开发程序 1.2 认识程序中的文件 1.3 Android程序结构 1.4 安卓程序打包 2. Android UI开发 2.1 布局的创 ...
最新文章
- Java File类总结和FileUtils类
- Oracle会话和进程数的监控
- python【数据结构与算法】Floyd算法模拟
- Flux --gt; Redux --gt; Redux React 入门 基础实例教程
- android 蒙版图片带拖动_推荐一个好用小巧的Android引导蒙版(浮层)库
- Pytest之收集用例及命令行参数
- 用cglib生成的代理类取不到注解的问题
- iOS charles 抓包使用
- 高中能学计算机吗,不读高中能把计算机这个行业学好吗
- java 求两点的角度_计算两点之间的角度 – java
- 【Windows】手机远程控制电脑
- 基于stm32的自动调速风扇
- 一看就会的侧方位停车技巧 见了就收了吧
- python 爬取图片、没有后缀名_python爬虫,图片是无格式的
- 关于ios9中得AddressBook和AddressBookUI框架过时问题
- [Mac] 安装软件时,出现 Waiting for other installations to complete
- 提高RM-MEDA局部学习(IRM-MEDA)
- [No000026]365种创业、办公、和生活成长的精华资源
- Python函数里的爱情故事
- 如何查询网站IP地址