-
LinearLayout线性布局
2018-09-28 22:33:03线性布局是一种非常常用的布局,它根据横向或者纵向排列控件,如果不设置横纵向,默认为横向排列 需要注意的是,如果排列方向是横向,内部的控件不能将宽设置为match_parenct,这样的话,单独一个控件就会将整个水平方向铺...线性布局是一种非常常用的布局,它根据横向或者纵向排列控件,如果不设置横纵向,默认为横向排列
需要注意的是,如果排列方向是横向,内部的控件不能将宽设置为match_parenct,这样的话,单独一个控件就会将整个水平方向铺满,其它的控件就没有可放置的位置了,同样的道理,纵向的高度也不能设置为match_parenct
常用属性为:
android:orientation="vertical" ----垂直排列
android:orientation="horizontal" ----横向排列
子控件常用属性为:
android:layout_gravity="center" ----设置控件显示位置,这里为居中显示
需要注意的是,如果排列方式为横向,那么给子控件设置居中,其实是垂直居中,因为横向还会增加控件,它的长度一直在改变,所以是上下垂直居中,垂直排列也一样,居中方式为横向居中
android:layout_weight="1" ----设置权重
权重解释:
假设权重为1和1和2,那么分别显示为四分之一,四分之一,四分之二(填满整个屏占比,横向或纵向)
设置横向显示权重:
app:layout_constraintHorizontal_weight="1"
设置纵向显示权重:
app:layout_constraintVertical_weight="1"
(相同线性下,有未设置权重的,未设置权重在占用固定比例后,权重根据特有比例去占用剩余空间)
-
Android计算器LinearLayout实现布局
2019-01-20 21:38:20计算器布局的实现有好多方法,先用LinearLayout实现一次吧,以后可能还会用其他布局 先上最终结果 实现方式是利用LinearLayout的layout_weight属性,实现按钮的均匀分布 由于layout_weight属性的特殊性, 当...计算器布局的实现有好多方法,先用LinearLayout实现一次吧,以后可能还会用其他布局
先上最终结果
实现方式是利用LinearLayout的layout_weight属性,实现按钮的均匀分布
由于layout_weight属性的特殊性,
当外层LinearLayout为垂直排布的时候,内部控件的layout_height要设为0dp,layout_width设为match_parent
当外层LinearLayout为水平排布的时候,内部控件的layout_width要设为0dp,layout_height设为match_parent
否则,最后的结果可能并不会像你想象得那样
这是一个简单到不能再简单的计算器了,只有加减乘除,
布局可以分为
第一行EditText layout_weight="1"
第二行,第三行,第四行分别有四个按钮 layout_weight="1"
第五行和第六行因为最后有一个占两行的等号
所以再嵌套一层
最外层的LinearLayout layout_weight=2
里边嵌套四个垂直排列的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>
第一个控件是一个EditText
设置从右到左编辑,点击不会唤醒键盘
<EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="end|bottom" android:editable="false"/>
剩下的就是LinearLayout里套Button 或者LinearLayout里套LinearLayout里再套Button了
全部代码如下,id起的不是很规范,英语渣(的不能再渣)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="end|bottom" android:editable="false"/> <!--第一行按钮c,÷,×,del--> <LinearLayout android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal"> <Button android:id="@+id/bt_clear" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:text="C"/> <Button android:id="@+id/bt_divide" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:text="÷"/> <Button android:id="@+id/bt_multiply" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:text="×"/> <Button android:id="@+id/bt_delete" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:text="del"/> </LinearLayout> <!--第二行按钮7,8,9,- --> <LinearLayout android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal"> <Button android:id="@+id/num7" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:text="7"/> <Button android:id="@+id/num8" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:text="8"/> <Button android:id="@+id/num9" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:text="9"/> <Button android:id="@+id/sub" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:text="-"/> </LinearLayout> <!-- 第三行按钮 4,5,6,+ --> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal"> <Button android:id="@+id/num4" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:text="4" /> <Button android:id="@+id/num5" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:text="5" /> <Button android:id="@+id/num6" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:text="6" /> <Button android:id="@+id/plus" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:text="+" /> </LinearLayout> <!-- 第四,五行按钮 --> <LinearLayout android:layout_weight="2" android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal"> <!-- 第一列按钮 1,% --> <LinearLayout android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/num1" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:text="1"/> <Button android:id="@+id/bt010" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:text="%"/> </LinearLayout> <!-- 第二列按钮 2 , 0 --> <LinearLayout android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/num2" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:text="2"/> <Button android:id="@+id/num0" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:text="0"/> </LinearLayout> <!-- 第三列按钮 3,. --> <LinearLayout android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/num3" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:text="3"/> <Button android:id="@+id/btpdot" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:text="."/> </LinearLayout> <!-- 第四列按钮 = --> <LinearLayout android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/bted" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:text="="/> </LinearLayout> </LinearLayout> </LinearLayout>
-
Android Studio App LinearLayout多层布局嵌套
2017-09-26 14:30:18LinearLayout内部嵌套LinearLayout activity_main.xml内容如下: [html] view plain copy print? LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=...LinearLayout内部嵌套LinearLayout
activity_main.xml内容如下:
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
- tools:context=".MainActivity"
- android:orientation="vertical">
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_weight="3"
- android:layout_height="wrap_content"
- >
- <EditText
- android:id="@+id/text"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_weight="10"
- android:layout_row="0"
- android:layout_column="0"
- />
- </LinearLayout>
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="3"
- >
- <Button
- android:id="@+id/seven"
- android:text="7"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- /><!--数字按钮7-->
- <Button
- android:id="@+id/eight"
- android:text="8"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- /><!--数字按钮8-->
- <Button
- android:id="@+id/nine"
- android:text="9"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- /><!--数字按钮9-->
- <Button
- android:id="@+id/divide"
- android:text="÷"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- />
- </LinearLayout>
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="3"
- >
- <Button
- android:id="@+id/four"
- android:text="4"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- /><!--数字按钮4-->
- <Button
- android:id="@+id/five"
- android:text="5"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- /><!--数字按钮5-->
- <Button
- android:id="@+id/six"
- android:text="6"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- /><!--数字按钮6-->
- <Button
- android:id="@+id/multiply"
- android:text="*"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- />
- </LinearLayout>
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="3"
- >
- <Button
- android:id="@+id/one"
- android:text="1"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- />/><!--数字按钮1-->
- <Button
- android:id="@+id/two"
- android:text="2"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- /><!--数字按钮2-->
- <Button
- android:id="@+id/three"
- android:text="3"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- /><!--数字按钮3-->
- <Button
- android:id="@+id/subtract"
- android:text="-"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- />
- </LinearLayout>
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="3"
- >
- <Button
- android:id="@+id/point"
- android:text="."
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- /><!--小数点-->
- <Button
- android:id="@+id/zero"
- android:text="0"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- /><!--数字按钮0-->
- <Button
- android:id="@+id/delete"
- android:text="←"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- />
- <Button
- android:id="@+id/add"
- android:text="+"
- android:textSize="20dp"
- android:layout_width="0dp"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- />
- </LinearLayout>
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="3"
- >
- <Button
- android:id="@+id/equal"
- android:text="="
- android:textSize="20dp"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- />
- </LinearLayout>
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="3"
- >
- <Button
- android:id="@+id/clear"
- android:text="Clear"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- />
- </LinearLayout>
- </LinearLayout>
-
LinearLayout布局
2016-08-31 10:45:32(1)LinearLayout的属性 高度 宽度 方向 8个上下左右的距离: // margin: 控件距离父View的距离:外部 // padding:内容距离控件的距离:内部 // android:gravity属性是对该对象内容的限定...<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"(1)LinearLayout的属性
高度
宽度
方向
8个上下左右的距离:
// margin:控件距离父View的距离:外部
// padding:内容距离控件的距离:内部
// android:gravity属性是对该对象内容的限定(往下)
比如一个button 上面的text.你可以设置该text在view的靠左,靠右等位置
// android:layout_gravity是用来设置该view相对于父view的位置(往上)
比如一个button 在linearlayout里,你想把该button放在靠左,靠右等位置就可以在linearlayout中通过该属性设置.
下面回到正题, 我们可以通过设置android:gravity="center"来让EditText中的文字在EditText组件中居中显示;同时我们设置EditText的android:layout_gravity="right"来让EditText组件在LinearLayout中居右显示。看下效果:
正如我们所看到的,在EditText中,其中的文字已经居中显示,而EditText组件自己也对齐到了LinearLayout的右侧
-
使用weight 让linearlayout内部的控件居中显示
2016-01-11 15:35:10之前都是使用相对布局进行居中控件的,今天看了一篇博客,突然明白,原来使用weight 可以让linearlayout内部的控件居中显示,实在腻害,下面就说下最近掌握的weight的使用方法 首先说下linearlayout使用weight来让... -
自定义 RadioGroup 使其内部嵌套LinearLayout布局实现按钮单选
2020-05-02 10:23:59自定义RadioGroup public class MyRadioGroup extends LinearLayout { // holds the checked id; the selection is empty by default private int mCheckedId = -1; // tracks children radio buttons che... -
Android布局之线性布局LinearLayout
2020-02-07 21:08:15LinearLayout内部视图的排列是有顺序的,要么从上到下,要么从左到右依次水平排列 LinearLayout特有XML属性 属性定义 属性说明 orientation 指定线性布局方向,horizontal表示水平布局,vertical表示垂直... -
android 入门 Linearlayout 布局 初级 activity之间数据传递 xml内部定义监听
2019-09-18 15:39:56BMI健康指数计算(最简单的按键监听“xml内部定义”) MainActivity.java: public class MainActivity extends Activity { EditText height,wei; Button comp,clear; double he... -
Activity中调用 自定义LinearLayout布局文件方法
2019-06-19 20:06:18``` public class LoginActivity extends BaseActivity { private LoginView mLoginView; @Override ... protected void onCreate(@Nullable ...//已经初始化的LinearLayout,外部调用更改内部布局,不生效怎么办 -
Android小知识——ScrollView内的内部嵌套LinearLayout布局导致滑动条占位置
2014-07-27 20:54:03ScrollView内部只能放一个zhen -
Android学习——LinearLayout布局实现居中、左对齐、右对齐
2019-10-07 16:16:09在整体垂直排列的基础上想要实现内部水平排列,则在整体LinearLayout布局下再创建一个LinearLayout布局。 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="... -
笔记 LinearLayout:线性布局管理器:
2019-06-14 13:55:04控制内部的组件纵向或者横向进行排列 分为垂直线性管理器和水平线性布局管理器 通过对android:orientation=”vertical/horizontal” 属性来进行两种线性布局管理器设置 垂直线性管理器每一行只能放置一个组件并且... -
安卓之线性布局LinearLayout
2019-05-04 12:29:00(2)gravity:指定布局内部视图与本线性布局的对齐方式 (3)layout_weight:指定当前视图的宽或高占上级线性布局的权重 二、在代码中增加LinearLayout的方法 (1)setOrientation:设置线性布局的方向 ... -
Android布局(二)之线性布局LinearLayout
2019-04-13 13:06:24顾名思义,就是在这样的布局下,所有的内部视图按照一定的次序有序排列,这个次序可以是水平方向,也可以是垂直方向。 一、线性布局LinearLayout的常用属性 在XML布局文件中,该次序的属性为: ori... -
android 流布局LinearLayout
2016-06-20 18:33:411.LinearLayout<LinearLayout xmlns:android=... android:layout_width="match_parent"//填充满父控 件wrap_content 围绕内部内容自适应 android:layout_height="match_parent -
android scrollView 内部子布局无法充满屏幕- LinearLayout not expanding inside a ScrollView
2016-10-12 10:35:30LinearLayout not expanding inside a ScrollView 解决问题链接: http://stackoverflow.com/questions/2599837/linearlayout-not-expanding-inside-a-scrollview Found the solution myself in the ... -
LinearLayout
2018-03-24 23:07:43LinearLayout线性布局是按照垂直或水平的方式进行排布的。默认是按照垂直进行排布。orientation用来指定当前线性布局的排布方向。水平horizontal、垂直verticalwrap_content 包裹内容match_parent 匹配父类margin... -
LinearLayout嵌套自定义子布局gravity无效
2017-07-20 11:27:15LinearLayout布局属性gravity在横向和竖向是部分有效的,比如一个横向的LinearLayout,内部有两个View,设置gravity底部对齐,会发现子View中高度小的那个没有贴住底部。 可以在子View外再嵌套一个Layout布局,这是... -
android四种基本布局之LinearLayout
2017-01-15 14:54:42LinearLayout(线性布局): LinearLayout 又称作线性布局,是一种非常常用的布局,android:orientation...这里需要注意,如果LinearLayout 的排列方向是horizontal,内部的控件就绝对不能将 宽度指定为match_parent, -
线性布局——LinearLayout
2016-05-03 21:33:54注意:layout表示的是父容器的意思,即如果有这个layout则是在父容器中的布局,如果没有是指内部的文字的高度和宽度简单的来说layout_width表示的就是在父容器中整个控件的位置width表示的就是控件中文字的位置(二... -
linearlayout布局的属性 gravity layout_gravity layout_weight
2017-08-20 23:48:52gravity表示在空间内部的对齐方式,他的针对效果是对内部来说的。对自己本身起作用。而layout_gravity是对这个控件在父类中的位置排布起作用的。二者的针对对象不同。 2.可以使用的属性 left right bottom等... -
Android---3---布局之LinearLayout
2015-04-06 15:25:41Android下有五大布局,分别是: LinearLayout 线性布局 ...布局是一种可用于放置很多控件的容器,它可以按照一定的规律调整内部控件的位置,从而编写出精美的界面。 1.LinearLayout LinearLayou -
Android的几种常用布局——LinearLayout,RelativeLayout和FrameLayout
2019-07-09 11:28:30顾名思义,LinearLayout下面的子视图就像用一根线串了起来,所以LinearLayout内部视图的排序是有顺序的,要么从上到下依次垂直排序,要么从左到右依次水平排列。LinearLayout除了继承View/ViewGroup类的所有属性和... -
Android常用布局及属性--LinearLayout
2016-02-18 15:16:37LinearLayout线性布局,它的子控件是以单一的行或者单一的列排列,子控件不能重叠,具有方向性(水平、垂直),默认是水平方向,可以设置位置和权重 * 常用的XML属性: android:orientation 线性布局的排列方向... -
安卓界面基础知识总结(一):LinearLayout布局的常见属性
2018-03-15 17:04:54之前做项目都是用到了才会查找自己所需的,没有系统总结一下,也没有特意去记,面试的时候被问到了居然不知道,-_-||决定开始系统总结一下:1.android:orientation:设置线性布局是水平还是竖直排列,可能选项如下:1... -
动态加载布局时设置LinearLayout中的View的权重
2017-03-10 09:30:55根据数量的多少动态加载LinearLayout的个数,每个LinearLayout内部是横向排列的三个TextView,要让每个TextView中的文字居中显示,三个TextView还要平均分布占满整个屏幕的宽度,即用JAVA代码设置每个TextView的android:... -
Android布局LinearLayout子控件无法填充问题
2012-08-10 14:49:13外层LinearLayout的android:orientation属性如果...内部的控件即使设置了android:layout_width="fill_parent",仍然无法达到内部控件充满 所以只需将外层LinearLayout的android:android:orientation设置为vertical即可 -
Android LinearLayout
2013-11-20 09:27:00Android LinearLayout 线性布局 可以设置orientation:vertical |horizontal 设置内部元素水平排列或者垂直排列 转载于:https://www.cnblogs.com/daxin/p/3432733.html -
Android学习笔记-3种基本布局(LinearLayout、RelativeLayout、FrameLayout)
2020-10-12 14:49:50当然,布局的内部除了放置控件外,也可以放置布局,通过多层布局的嵌套,我们就能够完成一些比较复杂的界面实现。 LinearLayout LinearLayout又称作线性布局,这个布局会将它所包含的控件在线性方向上依次排列。 &...
-
MySQL你该了解的那些事【服务端篇】
-
iptables 企业级防火墙配置(四表五链)
-
CS3100-UNO-源码
-
arwin:Visual C ++项目中的arwin-源码
-
Spring学习笔记之配置Bean
-
龙芯实训平台应用实战(希云)
-
Unity ILRuntime框架设计
-
Glasterfs 分布式网络文件系统
-
有赞容器化实践
-
常用的分布式事务解决方案
-
安卓Android全局变量
-
需求分析与建模最佳实践
-
2021 年该学的 CSS 框架 Tailwind CSS 实战视频
-
JMETER 性能测试基础课程
-
宏宇社:国外lead入门教程(四)lead任务必备软件
-
自动化测试Python3+Selenium3+Unittest
-
NFS 实现高可用(DRBD + heartbeat)
-
笔记
-
解决问题:这是解决问题的仓库-源码
-
select和epoll的过程分析与比较