Android线性布局与相对布局的实现
作者:少年白马 时间:2021-07-26 09:08:01
线性布局(LinearLayout)
名字 | 含义 |
---|---|
android:id | 设置一个id方便使用 |
android:layout_width | 宽度 |
android:layout_height | 高度 |
android:background | 设置背景颜色 |
android:layout_margin | 设置外边距 |
android:layout_padding | 设置内边距 |
android:orientation | 设置方向(水平或者垂直) |
练习代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/ll_1"
android:layout_width="200dp"
android:layout_height="200dp"
android:orientation="vertical"
android:background="#000000"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="50dp"
android:paddingBottom="10dp">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0033"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="horizontal"
android:background="#0066FF"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#000000"
android:layout_weight="1"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#FF0033"
android:layout_weight="1"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#55AA99"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
实现效果
相对布局(RelativeLayout)
最常用属性
名字 | 含义 |
---|---|
android:layout_toLeftOf | 在什么的左边 |
android:layout_toRightOf | 在什么的右边 |
android:layout_alignBottom | 跟什么底部对齐 |
android:layout_alignParentBottom | 与父控件底部对齐 |
android:layout_below | 在什么的底部 |
样例效果
<?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">
<View
android:id="@+id/view_1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#000000" />
<View
android:id="@+id/view_2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="@id/view_1"
android:background="#FF0033" />
<LinearLayout
android:id="@+id/ll_1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@id/view_2"
android:background="#0066FF"
android:orientation="horizontal"
android:padding="15dp">
<View
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#FF0033" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:padding="15dp">
<View
android:id="@+id/view_3"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#FF9900"/>
<View
android:id="@+id/view_4"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#FF9900"
android:layout_toRightOf="@id/view_3"
android:layout_marginLeft="10dp"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
实现效果
来源:https://blog.csdn.net/qq_44833724/article/details/122921579
标签:Android,线性布局,相对布局
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C# Windows API应用之基于FlashWindowEx实现窗口闪烁的方法
2023-06-30 12:55:22
java打印正弦曲线示例
2022-05-04 00:48:56
![](https://img.aspxhome.com/file/2023/5/129115_0s.jpg)
Java设计模式之享元模式实例详解
2021-12-19 17:54:00
Winform项目中TextBox控件DataBindings属性
2023-03-29 15:25:15
![](https://img.aspxhome.com/file/2023/0/86990_0s.jpg)
使用GPS经纬度定位附近地点(某一点范围内查询)
2023-08-22 18:49:09
Java中lambda表达式实现aop切面功能
2022-12-02 09:44:59
![](https://img.aspxhome.com/file/2023/5/84625_0s.png)
Android快速实现断点续传的方法
2021-06-14 13:02:28
使用Java将一个List运用递归转成树形结构案例
2021-10-14 15:18:30
![](https://img.aspxhome.com/file/2023/5/77485_0s.jpg)
C#开发WinForm清空DataGridView控件绑定的数据
2022-12-01 11:22:08
![](https://img.aspxhome.com/file/2023/7/91327_0s.jpg)
Java调用Shell命令的方法
2022-01-06 20:01:34
java用户管理注册功能 含前后台代码
2022-08-01 12:05:11
![](https://img.aspxhome.com/file/2023/1/132071_0s.jpg)
android实现倒计时功能(开始、暂停、0秒结束)
2021-09-29 11:02:29
Struts2实现文件上传时显示进度条功能
2021-10-13 05:22:22
Java实现经典游戏复杂迷宫
2021-05-29 22:33:34
![](https://img.aspxhome.com/file/2023/1/63301_0s.png)
解决Java中由于数据太大自动转换成科学计数法的问题
2022-01-24 17:31:45
C#遍历系统进程的方法
2021-09-24 15:35:29
C# 获取枚举值的简单实例
2023-09-01 00:13:23
Spring boot中PropertySource注解的使用方法详解
2022-07-30 02:29:57
![](https://img.aspxhome.com/file/2023/9/72539_0s.jpg)
C# Winfrom实现Skyline画直线功能的示例代码
2023-04-24 12:41:48
![](https://img.aspxhome.com/file/2023/9/111249_0s.jpg)
Android实现沉浸式导航栏实例代码
2023-02-18 02:15:17