安卓基本布局(上)

embedded/2024/10/21 11:30:08/

文章目录

      • LinerLayout线性布局
      • RelativeLayout相对布局
        • 根据父容器定位
        • 根据兄弟组件定位
        • margin偏移
        • padding填充

LinerLayout线性布局

  以水平或垂直的方式来排列界面中的控件。

常用属性详细描述
orientation布局中组件的排列方式。horizonta:水平;vertical:竖直(默认)。
gravity控制组件所包含的子元素的对齐方式,可以多个组合。
layout_gravity控制该组件在父容器里的对齐方式
layout_width布局宽度,wrap_content:组件实际大小;fill_parent、match_parent:填满父容器;固定值。
layout_height布局高度,wrap_content:组件实际大小;fill_parent、match_parent:填满父容器;固定值。
id为该组件设置一个资源id,在Java文件中可以通过findViewById找到该组件
background为该组件设置一个背景图片或直接用颜色覆盖
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/LinearLayout1"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"><LinearLayoutandroid:layout_width="0dp"android:layout_height="fill_parent"android:background="#ADFF2F"android:layout_weight="3"android:gravity="bottom|left"><Buttonandroid:layout_weight="1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="one"/><Buttonandroid:layout_weight="3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="two"/></LinearLayout><LinearLayoutandroid:layout_width="0dp"android:layout_height="fill_parent"android:background="#DA70D6"android:layout_weight="1"/></LinearLayout>

在这里插入图片描述

RelativeLayout相对布局

  通过相对定位的方式让控件出现在布局的任何位置。

基本属性详细描述
gravity设置容器内组件的对齐方式。
ignoreGravity该属性为true的组件,将不受gravity属性影响。
根据父容器定位
属性描述
layout_alignParentLeft左对齐
layout_alignParentRight右对齐
layout_alignParentTop顶部对齐
layout_alignParentBottom底部对齐
layout_centerHorizontal水平居中
layout_centerVertical垂直居中
layout_centerInParent中间居中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><!-- 1会被2覆盖--><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:text="1" /><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentTop="true"android:text="2" /><Buttonandroid:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_alignParentTop="true"android:text="3" /><Buttonandroid:id="@+id/button4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:text="4" /><Buttonandroid:id="@+id/button5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:text="5" /><!-- 6会被7覆盖--><Buttonandroid:id="@+id/button6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentBottom="true"android:text="6" /><Buttonandroid:id="@+id/button7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:text="7" /><Buttonandroid:id="@+id/button8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_alignParentBottom="true"android:text="8" /><Buttonandroid:id="@+id/button9"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:text="9" />
</RelativeLayout>

在这里插入图片描述

根据兄弟组件定位
属性描述
layout_toLeftOf参考组件的左边
layout_toRightOf参考组件的右边
layout_above参考组件的上方
layout_belove参考组件的下方
layout_alignTop对齐参考组件的上边界
layout_alignBottom对齐参考组件的下边界
layout_alignLeft对齐参考组件的左边界
layout_alignRight对齐参考组件的右边界
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/textview"android:layout_width="200dp"android:layout_height="200dp"android:background="#13d169"android:layout_centerInParent="true" /><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toLeftOf="@+id/textview"android:text="1" /><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toRightOf="@+id/textview"android:text="2" /><Buttonandroid:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/textview"android:text="3" /><Buttonandroid:id="@+id/button4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/textview"android:text="4" /><Buttonandroid:id="@+id/button5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignTop="@+id/textview"android:text="5" /><Buttonandroid:id="@+id/button6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBottom="@+id/textview"android:text="6" /><Buttonandroid:id="@+id/button7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/textview"android:text="7" /><Buttonandroid:id="@+id/button8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignRight="@+id/textview"android:text="8" />
</RelativeLayout>

在这里插入图片描述

margin偏移
属性描述
layout_margin设置组件上下左右的偏移量
layout_marginLeft设置组件离左边的偏移量
layout_marginRight设置组件离右边的偏移量
layout_marginTop设置组件离上面的偏移量
layout_marginBottom设置组件离下面的偏移量
padding填充
属性描述
padding向内部元素的上下左右填充一定边距
paddingLeft向内部元素的左边填充一定边距
paddingRight向内部元素的右边填充一定边距
paddingTop向内部元素的上方填充一定边距
paddingBottom向内部元素的下方填充一定边距

http://www.ppmy.cn/embedded/90189.html

相关文章

nginx的反向代理及负载均衡

nginx的反向代理 安装包链接https://nginx.org/download/nginx-1.26.1.tar.gz yum -y install gcc gcc-c pcre-devel openssl-devel [rootstaticserver ~]# tar -xzvf nginx-1.26.1.tar.gz [rootstaticserver nginx-1.26.1]#./configure --prefix/usr/local/nginx --userngi…

【JVM内存】系统性排查JVM内存问题的思路

【JVM内存】系统性排查JVM内存问题的思路 背景 前言 遇到过几次JVM堆外内存泄露的问题&#xff0c;每次问题的排查、修复都耗费了不少时间&#xff0c;问题持续几月、甚至一两年。我们将这些排查的思路梳理成一套系统的方法&#xff0c;希望能给对JVM内存分布、内存泄露问题…

CTFSHOW 萌新 web9 解题思路和方法(利用system函数执行系统命令)

点击题目链接&#xff0c;从题目页面显示的代码中可以看到我们可以使用命令执行漏洞查看网站的文件&#xff1a; 我们首先使用system函数并使用 ls 命令查看当前目录下的所有文件&#xff1a; 因为题目中提示flag在config.php文件中&#xff0c;所有可以直接读取该文件 当然&am…

alibaba cloud linux+JDK+TOMCAT+NGINX+PHP+MYSQL配置实践

CentOs要停止维护了&#xff0c;一直在服务器上用的CentOs7也最迟到2024年6月了&#xff0c;这次给公司新购一台备用服务器&#xff0c;在选择操作系统的时候&#xff0c;考虑了一下&#xff0c;决定试用一下阿里云的alibaba cloud linux。 alibaba cloud linux分为2和3版本&am…

window bat批处理脚本

参考&#xff1a; https://www.cnblogs.com/dirgo/p/18108455 https://blog.csdn.net/AnChenliang_1002/article/details/131288871 https://www.cnblogs.com/jingxian666/p/16814375.html 什么是BAT 全称即Batch&#xff0c;批处理&#xff0c;是一类可执行的文本文件&#…

Stable Diffusion绘画 | 文生图设置详解—随机种子数(Seed)

随机种子数&#xff08;Seed&#xff09; Midjourney 也有同样的概念&#xff0c;通过 --seed 种子数值 来使用。 每次操作「生成」所得到的图片&#xff0c;都会随机分配一个 seed值&#xff0c;数值不同&#xff0c;生成的画面就会不同。 默认值为 -1&#xff1a;每次随机分…

数据结构与算法--队列

文章目录 提要队列的定义队列的认识队列的应用队列的抽象数据类型队列的存储结构队列的链式存储结构与实现链队的进队和出队操作链队的数据类型初始化链队列入队操作出队操作队列的顺序存储结构与实现顺序队列的假溢出问题队列上溢循环队列循环队列取下一相邻单元下标运算队满与…

24年电赛——自动行驶小车(H题)基于 CCS Theia -陀螺仪 JY60 代码移植到 MSPM0G3507(附代码)

前言 只要搞懂 M0 的代码结构和 CCS 的图形化配置方法&#xff0c;代码移植就会变的很简单。因为本次电赛的需要&#xff0c;正好陀螺仪部分代码的移植是我完成的。&#xff08;末尾附全部代码&#xff09; 一、JY60 陀螺仪 JY60特点 1.模块集成高精度的陀螺仪、加速度计&…