Android-布局管理器

article/2025/9/28 0:22:17

线性布局(Linearlayout)

属性

orientation  布局管理器内组件的排列方式(horizontal(水平)和vertical(垂直),默认值为                 horizontal.)

layout_weight   权重  à  用于设置组件占父容器剩余空间的比例

layout_backgound 背景颜色

layout_gravity  设置当前组件在布局管理器中的位置

示例

代码

<?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" ><Button android:id="@+id/tv_bt1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt1"android:layout_weight="2"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content" android:background="#90f0"android:layout_weight="2"    ><Button android:id="@+id/tv_bt4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt4"android:layout_gravity="center"/>    <Button android:id="@+id/tv_bt5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt5"android:layout_weight="2"android:layout_gravity="right|bottom"        />                </LinearLayout><Button android:id="@+id/tv_bt2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt2"/>    <Button android:id="@+id/tv_bt3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt3"android:layout_weight="1"/>
</LinearLayout>

显示

相对布局(RelativeLayout)

需要设置id属性

因为相对布局需要以其它控件(id)或父容器作为参照, 后放入控件的位置依赖于先放入的控件。

属性

控件属性

功能描述

android:layout_centerInParent

设置当前控件位于父布局的中央位置,

其属性值为boolean值

android:layout_centerVertical

设置当前控件位于父布局的垂直居中位置,

其属性值为boolean值

android:layout_centerHorizontal

设置当前控件位于父控件的水平居中位置

其属性值为boolean值

android:layout_above

设置当前控件位于某控件上方,

其属性值为其他UI组件的id属性

android:layout_below

设置当前控件位于某控件下方

其属性值为其他UI组件的id属性

android:layout_toLeftOf

设置当前控件位于某控件左侧

其属性值为其他UI组件的id属性

android:layout_toRightOf

设置当前控件位于某控件右侧

其属性值为其他UI组件的id属性

android:layout_alignParentTop

设置当前控件停靠于布局顶端

其属性值为boolean值

android:layout_alignParentLeft

设置当前控件停靠于布局左侧

其属性值为boolean值

android:layout_alignParentRight

设置当前控件停靠于布局右侧

其属性值为boolean值

android:layout_alignParentBottom

设置当前控件停靠于布局底端

其属性值为boolean值

                                              

                                                        设置当前控件的上边界与某控件的上边界对齐

android:layout_alignTop

设置当前控件的上边界与某控件的上边界对齐,

其属性值为其他UI组件的id属性

android:layout_alignBottom

设置当前控件的下边界与某控件的下边界对齐

其属性值为其他UI组件的id属性

android:layout_alignLeft

设置当前控件的左边界与某控件的左边界对齐

其属性值为其他UI组件的id属性

android:layout_alignRight

设置当前控件的右边界与某控件的右边界对齐

其属性值为其他UI组件的id属性

                                                           

                                                                设置当前控件边界与某控件的距离

android:layout_marginTop

设置当前控件上边界与某控件的距离

android:layout_marginBottom

设置当前控件底边界与某控件的距离

android:layout_marginLeft

设置当前控件左边界与某控件的距离

android:layout_marginRight

设置当前控件右边界与某控件的距离

 

示例

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent" ><Button android:id="@+id/bt1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt1"/><Button android:id="@+id/bt2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:text="bt2"/><Button android:id="@+id/bt3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:text="bt3"/><Button android:id="@+id/bt4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:text="bt4"/><Button android:id="@+id/bt5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:text="bt5"/><Button android:id="@+id/bt6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_centerVertical="true"        android:text="bt6"/><Button android:id="@+id/bt7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:text="bt7"/><Button android:id="@+id/bt8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:text="bt8"/><Button android:id="@+id/bt9"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_alignParentRight="true"android:text="bt9"/><Button android:id="@+id/bt10"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@id/bt1"android:layout_toRightOf="@id/bt4"android:layout_above="@id/bt4"android:layout_alignRight="@id/bt2"android:text="bt10"/><Button android:id="@+id/bt11"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@id/bt10"android:layout_above="@id/bt7"android:layout_toRightOf="@id/bt4"android:text="bt11"/><Button android:id="@+id/bt12"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@id/bt5"android:layout_below="@id/bt5"android:layout_toLeftOf="@id/bt6"android:layout_alignBaseline="@id/bt11"android:text="bt12"/></RelativeLayout>

表格布局(Tablelayout)

表格布局属性

控件属性

功能描述

android:layout_column

设置该单元显示位置

android:layout_span

设置该单元格占据几行,默认为1

 表格布局中控件属性

控件属性

功能描述

android:layout_column

设置该单元显示位置

android:layout_span

设置该单元格占据几行,默认为1

示例

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:stretchColumns="1,2" ><TableRow android:layout_width="match_parent"android:layout_height="wrap_content"><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="点a:"/><EditText android:id="@+id/et_ax"android:layout_width="wrap_content"android:layout_height="wrap_content"android:hint="x"/><EditText android:id="@+id/et_ax"android:layout_width="wrap_content"android:layout_height="wrap_content"android:hint="y"/></TableRow><TableRow android:layout_width="match_parent"android:layout_height="wrap_content"><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="点b:"/><EditText android:id="@+id/et_bx"android:layout_width="wrap_content"android:layout_height="wrap_content"android:hint="x"/><EditText android:id="@+id/et_bx"android:layout_width="wrap_content"android:layout_height="wrap_content"android:hint="y"/></TableRow><Button android:id="@+id/bt"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="确定"/></TableLayout>

帧布局(FrameLayout)

示例

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:foreground="@drawable/ic_launcher"   android:foregroundGravity="right|bottom" ><TextView android:layout_gravity="center"android:layout_width="400px"android:layout_height="400px"android:background="#f00"android:text="红色背景的TextView"/><TextView android:layout_gravity="center"android:layout_width="300px"android:layout_height="300px"android:background="#FF8000"android:text="橙色背景的TextView"/><TextView android:layout_gravity="center"android:layout_width="200px"android:layout_height="200px"android:background="#FFFF00"android:text="黄色背景的TextView"/></FrameLayout>

 网格布局(GridLayout)

 示例

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent" android:columnCount="4"><Button android:id="@+id/bt1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt1"android:layout_column="3"/><Button android:id="@+id/bt2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt2"/><Button android:id="@+id/bt3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt3"/><Button android:id="@+id/bt4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt4"/><Button android:id="@+id/bt5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt5"/><Button android:id="@+id/bt6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt6"/><Button android:id="@+id/bt7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt7"/><Button android:id="@+id/bt8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt8"/><Button android:id="@+id/bt9"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt9"/><Button android:id="@+id/bt10"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt10"/><Button android:id="@+id/bt11"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt11"/><Button android:id="@+id/bt12"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt12"/><Space /><Button android:id="@+id/bt13"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt13"android:layout_columnSpan="2"android:layout_gravity="fill_horizontal"/><Button android:id="@+id/bt14"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="bt14"/><Button android:id="@+id/bt15"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_rowSpan="2"android:layout_gravity="fill_vertical"android:text="bt15"/><Button android:id="@+id/bt16"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnSpan="3"android:layout_gravity="fill_horizontal"android:text="bt16"/><Space /></GridLayout>

 


http://chatgpt.dhexx.cn/article/Hc7ila06.shtml

相关文章

android 布局

android学习笔记&#xff08;一 android布局学习&#xff09; 转自http://blog.sina.com.cn/s/blog_61c62a960100ev3q.html (2009-09-20 20:50:44) 转载 标签&#xff1a; it 分类&#xff1a;android 最近痴迷上了android &#xff0c; 因为有java 语言的基础学起来自己感觉很…

安卓六大布局介绍

安卓六大布局 布局的介绍安卓六大布局 布局的介绍 用户使用安卓看到的应用界面&#xff0c;是通过布局和组件构成的&#xff0c;组件根据布局的格式排列&#xff0c;形成用户所看到的界面。 安卓六大布局 线性布局方式&#xff08;LinearLayout&#xff09; 按照垂直或者水平…

安卓线性布局

安卓线性布局 &#xff08;一&#xff09;界面与布局1、界面2、布局&#xff08;1&#xff09;UI容器&#xff08;2&#xff09;UI控件 (Control)&#xff08;3&#xff09;两种方式声明布局 &#xff08;二&#xff09;线性布局&#xff08;1&#xff09;常用属性 &#xff08…

安卓的常用布局看一篇就够了

目录 1-1 布局通用的属性 1-2 线性布局&#xff08;LinearLayout&#xff09; 1、常见属性&#xff1a; 2、线性布局的例子&#xff1a; 1-3 相对布局&#xff08;RelativeLayout&#xff09; 1、常见属性&#xff1a; 2、 相对布局的例子&#xff1a; 1-4 帧布局&a…

android布局技巧:创建高效布局

Android UI工具包提供了一些布局管理器&#xff0c;它们使用起来相当容易&#xff0c;而且&#xff0c;大多数的时候&#xff0c;你只需要使用它们最基本的特征来实现UI。 执着于基本特征的使用对于创建UI来说&#xff0c;往往不是最高效的。一个常见的例子就是滥用LinearLayo…

安卓7大基本布局

一&#xff1a;基础知识 1.Android七大基本布局分别是&#xff1a; LinearLayout(线性布局)、TableLayout(表格布局)、RelativeLayout(相对布局)、FrameLayout(层布局)、AbsoluteLayout(绝对布局)、GridLayout(网格布局)、ConstraintLayout(约束布局)。 2.七大基本布局的继承…

Android的六大基本布局

线性布局 LinearLayout相对布局 RelativeLayout表格布局 TableLayout绝对布局 AbsoluteLayout网格布局 GridLayout帧布局 FrameLayout 布局通用属性 属性名称功能描述android:id设置布局的标识android:layout_width设置布局的宽度android:layout_height设置布局的高度android:…

安卓布局详解:探索各种布局方式

文章目录 前言一、线性布局&#xff08;LinearLayout&#xff09;二、相对布局&#xff08;RelativeLayout&#xff09;三、帧布局&#xff08;FrameLayout&#xff09;四、表格布局&#xff08;TableLayout&#xff09;五、约束布局&#xff08;ConstraintLayout&#xff09;六…

微信小程序页面布局——上中下结构

小程序页面布局——上中下结构 内容简述 上中下结构&#xff1a;头脚固定中间滚动框 使用UI框架&#xff1a;Vant Weapp(引入安装参考) 为了方便&#xff0c;使用了less生成wxss&#xff0c;所以展示的是less代码&#xff0c;有需要可以看&#xff1a;https://www.jianshu.com…

微信小程序中的常用布局方式(总结)

参照Android开发&#xff0c;总结了微信小程序的常用的两种布局方式&#xff1a;1、线性布局&#xff08;横版、竖版&#xff09;。2、网格布局。 效果图如下&#xff1a; 一、网格布局 &#xff08;1&#xff09;固定Item个数的网格布局&#xff0c;主要用于功能模块入口展示…

微信小程序页面布局

一,微信小程序页面布局方式采用的是Flex布局 1.Flex布局&#xff0c;是W3c在2009年提出的一种新的方案&#xff0c;可以简便&#xff0c;完整&#xff0c;响应式的实现各种页面布局。 2.Flex布局提供了元素在容器中的对齐&#xff0c;方向以及顺序&#xff0c;甚至他们可以是动…

html的网格布局

网格布局 学习总结&#xff1a; 从7.19进入csdn夏令营后&#xff0c;感谢各位老师的辛苦讲解与发布任务&#xff0c;我对C1能力认证中web方面的知识有了极大的领会。学习过程中既温习了在校学习的知识&#xff0c;也学到了诸如网格布局&#xff0c;动画&#xff0c;less&#x…

网格布局(grid布局)

网格布局 他可以将页面分为多个网格&#xff0c;可以任意组合不同的网格 &#xff0c;做出各种各样的布局。 网格布局为二维性质的。 设置行、列间距 grid-row-gap:1rem ;行间距 ** grid-column-gap: 1rem ;列间距** ** grid-gap: 1rem;**设置行列间距 设置容器的列宽和与…

CSS布局—网格布局Grid(一)

CSS网格可以定义由行和列组成的二维布局&#xff0c;然后将元素放置到网格中。有些元素可能只占据网格的一个单元&#xff0c;另一些元素则可能占据多行或多列。网格的大小既可以精确定义&#xff0c;也可以根据自身内容自动计算。你既可以将元素精确地放置到网格某个位置&…

CSS Grid 网格布局教程

一、概述 网格布局&#xff08;Grid&#xff09;是最强大的 CSS 布局方案。 它将网页划分成一个个网格&#xff0c;可以任意组合不同的网格&#xff0c;做出各种各样的布局。以前&#xff0c;只能通过复杂的 CSS 框架达到的效果&#xff0c;现在浏览器内置了。 上图这样的布局&…

css 网格布局

简介&#xff1a; 网格是由一系列水平及垂直的线构成的一种布局模式。一个网格通常具有许多的列&#xff08;column&#xff09;与行&#xff08;row&#xff09;&#xff0c;以及行与行、列与列之间的间隙&#xff0c;这个间隙一般被称为沟槽&#xff08;gutter&#xff09;。…

微信小程序的页面布局(1)

微信小程序的页面布局主要用到两个文件&#xff0c;wxml&#xff08;摆放各种组件&#xff09;和wxss&#xff08;设计排版&#xff09; 因此&#xff0c;我们首先将要用到的组件按照一定的组织排序扔进wxml文件里&#xff0c;什么叫组织排序呢&#xff0c;这里注意就是组件与组…

微信小程序~利用模板实现《福利》页面的网格布局

什么是模板&#xff1f; 在微信小程序中&#xff0c;使用template来表示模板 为什么要使用模板&#xff1f; 使用模板文件能够降低代码重构&#xff0c;提高代码的复用性。 如何使用&#xff1f; 页面内使用&#xff1a;在页面内直接声明一个template并且引用代码如下&#xf…

【HTML/CSS】网格布局小案例

代码如下&#xff08;可以改动精简一些&#xff0c;我不想改了&#xff0c;改一下估计50行就够了&#xff09;&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta http-equiv"X-UA-Compati…

微信小程序第三天(布局:栅格布局)

我根据微信小程序的特点弄了一套简单的栅格布局。 .row {display: block;margin: 0px; }.col {display: flex;font-family: -apple-system-font, "Helvetica Neue", sans-serif;font-size: 17px; }.col>.col-1, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7,…