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

Android Studio六大基本布局的概览和每个布局的关键特性以及实例分析

1. 线性布局 (LinearLayout)

描述
线性布局是一种按指定方向(水平或垂直)排列其子视图的布局容器。通过android:orientation属性可设置为horizontalvertical

关键属性

  • android:orientation: 指定布局方向。
  • android:layout_weight: 子视图权重,用于分配剩余空间。

示例

<LinearLayoutandroid:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:layout_width="wrap_content"android:layout_height="0dp"android:layout_weight="1" /><Buttonandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="2" /></LinearLayout>

2. 相对布局 (RelativeLayout)

描述
相对布局允许子视图相对于其他视图或父容器的位置进行定位,而不是基于屏幕坐标系。

关键属性

  • android:layout_alignParentLeft/Right/Top/Bottom: 相对于父容器对齐。
  • android:layout_toLeftOf/toRightOf/below/above: 相对于兄弟视图定位。
  • android:layout_centerInParent: 在父容器中心对齐。
  • android:layout_centerHorizontal/Vertical: 在水平或垂直方向居中。

示例

<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Title"android:layout_centerHorizontal="true" /><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Click me"
http://www.lryc.cn/news/299356.html

相关文章:

  • 【go语言】一个简单HTTP服务的例子
  • LeetCode Python - 15.三数之和
  • C#中implicit和explicit
  • 探讨java系统中全局唯一ID实现方案
  • 微信小程序(四十四)鉴权组件插槽-登入检测
  • 【ES】--ES集成热更新自定义词库(字典)
  • 能源管理师——为能源可持续发展护航
  • 设计模式理解:单例模式+工厂模式+建设者模式+原型模式
  • DataX源码分析 writer
  • 为自己的项目媒体资源添加固定高度
  • 家政小程序系统源码开发:引领智能生活新篇章
  • 多表查询
  • PHP开发日志 ━━ 深入理解三元操作与一般条件语句的不同
  • 多维时序 | Matlab实现RF-Adaboost随机森林结合Adaboost多变量时间序列预测
  • vue3-内置组件-Suspense
  • Rust入门:如何在windows + vscode中关闭程序codelldb.exe
  • git错误整理
  • 跟着cherno手搓游戏引擎【22】CameraController、Resize
  • 微信小程序(四十二)wechat-http拦截器
  • tomcat部署zrlog
  • Ubuntu Desktop 开机数字小键盘
  • 树莓派编程基础与硬件控制
  • autojs通过正则表达式获取带有数字的text内容
  • Android java基础_类的继承
  • nginx stream proxy 模块的ssl连接源码分析
  • C#面:Static Nested Class 和 Inner Class 有什么不同
  • LeetCode、208. 实现 Trie (前缀树)【中等,自定义数据结构】
  • java数据结构与算法刷题-----LeetCode151. 反转字符串中的单词
  • 《Java 简易速速上手小册》第8章:Java 性能优化(2024 最新版)
  • mysql全国省市县三级联动创表sql(一)