当前位置: 首页 > news >正文

安卓基本布局(上)

文章目录

      • 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向内部元素的下方填充一定边距

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • CCleaner安卓专业版:全方位手机清理工具,极速提升设备性能
  • 环境搭建:如何在 Windows 上安装和配置 Apache Maven 3.9.8
  • python:基于YOLO框架和遥感图像的目标检测
  • 【安当产品应用案例100集】005-安当ASP实现Exchange双因素登录认证
  • uniapp App地图点击label
  • 在Stable Diffusion中驱动Tesla P40
  • <数据集>柑橘缺陷识别数据集<目标检测>
  • SQL注入实例(sqli-labs/less-8)
  • freeRTOS入门学习-基于STM32F103C8T6最小系统板-使用cubeMX创建一个新的工程
  • SpringBoot 框架学习笔记(七):Thymeleaf、拦截器 和 文件上传实现(解决了文件重名 和 按日期分目录存放问题)
  • Qt/C++最新地图组件发布/历时半年重构/同时支持各种地图内核/包括百度高德腾讯天地图
  • 大数据项目——广告数仓之HTTP概述
  • centos开启samba服务
  • flutter路由配置
  • 使用Python实现深度学习模型:智能垃圾分类与环境保护
  • __proto__ 和 prototype的关系
  • 【5+】跨webview多页面 触发事件(二)
  • 【笔记】你不知道的JS读书笔记——Promise
  • ECMAScript入门(七)--Module语法
  • Java 多线程编程之:notify 和 wait 用法
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • Linux学习笔记6-使用fdisk进行磁盘管理
  • React系列之 Redux 架构模式
  • React中的“虫洞”——Context
  • seaborn 安装成功 + ImportError: DLL load failed: 找不到指定的模块 问题解决
  • Three.js 再探 - 写一个跳一跳极简版游戏
  • Web Storage相关
  • WePY 在小程序性能调优上做出的探究
  • XForms - 更强大的Form
  • 关于Android中设置闹钟的相对比较完善的解决方案
  • 可能是历史上最全的CC0版权可以免费商用的图片网站
  • 前端知识点整理(待续)
  • 如何解决微信端直接跳WAP端
  • 使用 Node.js 的 nodemailer 模块发送邮件(支持 QQ、163 等、支持附件)
  • 通过获取异步加载JS文件进度实现一个canvas环形loading图
  • 移动端 h5开发相关内容总结(三)
  • 测评:对于写作的人来说,Markdown是你最好的朋友 ...
  • ​LeetCode解法汇总2583. 二叉树中的第 K 大层和
  • #define
  • #define用法
  • #WEB前端(HTML属性)
  • (16)Reactor的测试——响应式Spring的道法术器
  • (arch)linux 转换文件编码格式
  • (delphi11最新学习资料) Object Pascal 学习笔记---第13章第6节 (嵌套的Finally代码块)
  • (Java企业 / 公司项目)点赞业务系统设计-批量查询点赞状态(二)
  • (Java入门)抽象类,接口,内部类
  • (ZT) 理解系统底层的概念是多么重要(by趋势科技邹飞)
  • (八)光盘的挂载与解挂、挂载CentOS镜像、rpm安装软件详细学习笔记
  • (附源码)springboot教学评价 毕业设计 641310
  • (机器学习-深度学习快速入门)第三章机器学习-第二节:机器学习模型之线性回归
  • (七)Activiti-modeler中文支持
  • (译)2019年前端性能优化清单 — 下篇
  • (幽默漫画)有个程序员老公,是怎样的体验?
  • (原創) X61用戶,小心你的上蓋!! (NB) (ThinkPad) (X61)
  • (转载)在C#用WM_COPYDATA消息来实现两个进程之间传递数据