Androidx学习笔记(6)--常见布局--线性布局
来源:互联网 发布:flash as2.0与js通信 编辑:程序博客网 时间:2024/06/06 13:51
线性布局
LinearLayout
指定各个节点的排列方向
android:orientation="horizontal"
设置右对齐
android:layout_gravity="right"
- 当竖直布局时,只能左右对齐和水平居中,顶部底部对齐竖直居中无效
- 当水平布局时,只能顶部底部对齐和竖直居中
- 使用match_parent时注意不要把其他组件顶出去
线性布局非常重要的一个属性:权重
android:layout_weight="1"
权重设置的是按比例分配剩余的空间,并且要设置layout_width或layout_height要为0
- 有一个布局方向,水平或者竖直
- 在竖直布局下,左对齐、右对齐,水平居中生效
- 在水平布局下,顶部对齐、底部对齐、竖直居中生效
- 权重:按比例分配屏幕的剩余宽度或者高度
示例:
布局代码
<?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" > <LinearLayout android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal" > <TextView android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:background="#ff0000" /> <TextView android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:background="#ffffff" /> <TextView android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:background="#000000" /> <TextView android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:background="@android:color/darker_gray" /> </LinearLayout> <LinearLayout android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:orientation="vertical" > <TextView android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:background="#00ff00" /> <TextView android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:background="@android:color/darker_gray" /> <TextView android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:background="#000000" /> <TextView android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:background="#ffcc0000" /> </LinearLayout></LinearLayout>
0 0
- Androidx学习笔记(6)--常见布局--线性布局
- Androidx学习笔记(7)--常见布局--相对布局
- Androidx学习笔记(8)--常见布局--帧布局
- Androidx学习笔记(33)---新闻客户端之布局
- Android学习 (六) 常见布局之线性布局
- android 布局学习---线性布局
- android学习笔记1:线性布局
- android学习笔记7:线性布局
- Android学习笔记06:线性布局LinearLayout
- Android学习笔记(11):线性布局LinearLayout
- Android学习笔记:线性布局LinearLayout
- 【Andorid学习笔记】常见的UI布局
- 安卓布局基础笔记(LinearLayout -- 线性布局 )
- Android学习分享-常用布局01-LinearLayout(线性布局)
- Android学习(十一)五布局之线性布局
- 详细学习线性布局(1)
- 详细学习线性布局(2)
- Android线性布局及帧布局学习
- 【python】获取三维图形的某个截面
- Fragment的生命周期
- Jav多线程
- 程序员常去的6个头条分享站点
- leetcode之delete Node in a linked list
- Androidx学习笔记(6)--常见布局--线性布局
- 2015 年度新增开源软件排名TOP100
- UIImageView常用操作
- 学习笔记------数据结构(C语言版)进制转换
- hdoj2050折线分割平面
- Linux下gcc生成和使用静态库和动态库详解
- 逆转字符串的一个快捷方法
- Java中的访问修饰符,this关键字,内部类
- halcon模板匹配