1、相对布局——RelativeLayout

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

如果不指定控件摆放的位置,控件都会被默认放在RelativeLayout的左上角。因此要先指定一个控件的位置,其他控件为该位置的相对位置。在相对布局里,id就显得尤为重要。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:id="@+id/button"android:layout_width="138dp"android:layout_height="114dp"android:text="铅笔"android:textSize="30sp"app:backgroundTint="#673AB7" /><Buttonandroid:id="@+id/button4"android:layout_width="138dp"android:layout_height="114dp"android:layout_below="@id/button"android:layout_toRightOf="@id/button"android:text="橡皮"android:textSize="30sp"app:backgroundTint="#FF5722" /><Buttonandroid:id="@+id/button5"android:layout_width="138dp"android:layout_height="114dp"android:layout_below="@id/button4"android:text="尺子"android:textSize="30sp"app:backgroundTint="#673AB7" />
</RelativeLayout>

2、线性布局(LinearLayout)

线性布局的控件依次排序,谁也不会覆盖谁,横向(Android:orientation="horizontal")
或纵向(android:orientation="vertical")

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#FFFFFF"android:gravity="clip_horizontal|clip_vertical|center_horizontal|center_vertical"android:orientation="vertical"><Buttonandroid:id="@+id/button1"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="top"android:layout_weight="1"android:background="#F44336"android:text="大草莓"android:textColor="#FFFFFF"android:textSize="30sp" /><Buttonandroid:id="@+id/button2"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:text="大西瓜"android:textSize="30sp" /><Buttonandroid:id="@+id/button3"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:text="大番茄"android:textSize="30sp" />
</LinearLayout>

3、表格布局(TableLayout)

直接往TableLayout中添加组件,那么这个组件将占满一行,TableRow是容器,把多个组件放在里面。TableRow的宽度会占满父布局,设置其他值不生效。表格的行数由TableRow的个数决定。

<?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"><TableRowandroid:layout_weight="1"android:layout_width="match_parent"android:layout_height="0dp"><LinearLayoutandroid:gravity="center"android:layout_weight="1"android:layout_width="0dp"android:layout_height="match_parent"android:orientation="horizontal"><TextViewandroid:textSize="100dp"android:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="0"android:text="猫咪"/></LinearLayout><LinearLayoutandroid:gravity="center"android:layout_weight="1"android:layout_width="0dp"android:layout_height="match_parent"android:orientation="horizontal"><TextViewandroid:textSize="100dp"android:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="0"android:text="金鱼"/></LinearLayout></TableRow><TableRowandroid:layout_weight="1"android:layout_width="wrap_content"android:layout_height="0dp"><LinearLayoutandroid:gravity="center"android:layout_weight="1"android:layout_width="0dp"android:layout_height="match_parent"android:orientation="horizontal"><TextViewandroid:textSize="100dp"android:id="@+id/textView3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="0"android:text="兔子"/></LinearLayout><LinearLayoutandroid:gravity="center"android:layout_weight="1"android:layout_width="0dp"android:layout_height="match_parent"android:orientation="horizontal"><TextViewandroid:textSize="100dp"android:id="@+id/textView4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="0"android:text="老虎"/></LinearLayout></TableRow>
</TableLayout>

4、网格布局(GridLayout)

一般用于制作类似计算器的页面。

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:columnCount="4"android:rowCount="4"android:orientation="horizontal"><Button android:text="/"android:layout_column="3"/><Button android:text="1"/><Button android:text="2"/><Button android:text="3"/><Button android:text="*"/><Button android:text="4"/><Button android:text="5"/><Button android:text="6"/><Button android:text="-"/><Button android:text="7"/><Button android:text="8"/><Button android:text="9"/><Button android:text="+"android:layout_gravity="fill"android:layout_rowSpan="2"/><Button android:text="0"/><Button android:text="="android:layout_gravity="fill"android:layout_columnSpan="2"/>
</GridLayout>

5、帧布局(FrameLayout)

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"><Buttonandroid:id="@+id/button10"android:layout_width="350dp"android:layout_height="350dp"android:text="四季"android:textSize="60dp" /><Buttonandroid:id="@+id/button11"android:layout_width="216dp"android:layout_height="140dp"android:text="春天"android:textSize="40dp" /><Buttonandroid:id="@+id/button12"android:layout_width="100dp"android:layout_height="wrap_content"android:text="发芽"android:textSize="20dp"/>
</FrameLayout>


啊请原谅今日份的划水博客,后面再抽时间来完善和补充吧!

Android Studio | 页面布局相关推荐

  1. android studio页面布局代码,还在用Android正经布局来写页面吗?

    来源:24K纯帅 ConstraintLayout布局出来已经很久了,刚出来那会儿就想尝试一下的,结果半天都没适应,前两天看到一篇ConstraintLayout实战的文章,看完之后发现这布局贼鸡儿好 ...

  2. android studio 页面布局

    哈哈哈,首先我也是初学android studio 这个软件,在Android中首先要学会布局, ①在布局中Design界面可以通过Palette中控件拖动到界面布局中 ②可通过在split界面编写代 ...

  3. Android Studio 线性布局Linearlayout的控件位置控制l属性Layout_margin失效问题解决

    Android Studio 线性布局Linearlayout的控件位置控制l属性Layout_margin失效问题解决 问题:如layout_marginRight ="50dp" ...

  4. Android的页面布局

    1. Android的基础布局                                 LinearLayout 线性布局 RelativeLayout 相对布局 TableLayout 表格 ...

  5. 设置Android Studio工程布局文件的默认布局

    每次创建新的工程后,布局文件的的布局总是ConstraintLayout,如何更改? 进入Android Studio安装目录,用文本编辑器打开文件plugins\android\lib\templa ...

  6. Android Studio:线性布局

    目录 一.导入新课 二.新课讲解 (一)界面与布局 1.界面 2.布局 (1)视图层次结构图 (3)UI控件 (Control) (4)两种方式声明布局 (二)线性布局 1.继承关系图 2.常用属性 ...

  7. android studio线性布局做计算器,Android Studio线性布局元素Listen

    我对android studio相当陌生,有点迷茫. 我有一个线性布局,最终会有图像的子代.这些孩子被认为是我手中的牌.当轮到我的时候,我会在线性布局中添加一个项目,当我点击一个卡片时,它将被移除. ...

  8. Android studio线性布局用户界面设计

    Android studio通过线性布局完成一个简单的个人信息的用户界面布局设计 线性布局需要考虑的就是水平还是垂直,通过 LinearLayout标签的一个必要属性android:orientati ...

  9. android studio线性布局做计算器,Android studio设计简易计算器

    本文实例为大家分享了Android studio设计简易计算器的具体代码,供大家参考,具体内容如下 效果显示: 第一步,简单的界面布局 xmlns:tools="http://schemas ...

最新文章

  1. 计算机语言编程能力有哪些,除了编程语言,程序员还需要具备哪些能力
  2. R语言使用yardstick包的roc_curve函数评估多分类(Multiclass)模型的性能、查看模型在多分类每个分类上的ROC曲线(roc curve)
  3. DarknetTiny模型结构
  4. php的数据校验,php 数据类型校验函数的简单示例
  5. java实例_图例 | Java混合模式分析之火焰图实例
  6. Java并发编程(五):Java线程安全性中的对象发布和逸出
  7. matlab simulink笔记08——from workspace和from file模块的区别
  8. 究极日月服务器维护时间,超激斗梦境9月25日终极测试服务器维护公告_超激斗梦境9月25日更新了什么_玩游戏网...
  9. java oracle数据库连接代码,java连接oracle数据库代码实例(注释详解)
  10. navicat执行.sql文件
  11. js css自动幻灯片切换,非常漂亮的JS+CSS图片幻灯切换特效
  12. dxf文件怎么转换成dwg?这种方法了解一下
  13. 10个办法带你提高工作效率
  14. AsposeWord转pdf的正确姿势
  15. 推荐一款HTML在线编辑器
  16. php自动生成phpunit,PHP单元测试利器 PHPUNIT深入用法(三)
  17. 【机密】从此没有难做的floorplan(数字后端设计实现floorplan篇)
  18. Qt的gui编程是,点击一次button出现两次action
  19. 手把手教你用 Java 实现word、excel、ppt、txt等办公文件在线预览功能!
  20. ZZULIOJ-1088,手机短号 (多实例)(Python)

热门文章

  1. 华为FPGA设计设计规范
  2. PhoneGap移动开发框架
  3. EXCEL 制作三维散点图
  4. 利用LANDesk Management进行软件的打包步骤
  5. ISC 2022“护航数字山河·数据安全协同创新”高峰会:共议数据安全新方案
  6. Java实习面试重点基础知识
  7. 关于银河麒麟系统配置本地yum源配置流程说明
  8. 游戏设计文档的功能及类型
  9. 【轻松学】python中文件的读和写——open、read或readline、close
  10. 灵活用工:一副2020失业潮的灵丹妙药?