当前位置:网站首页>Androd Day02
Androd Day02
2022-08-04 05:28:00 【N_Y_S】
重点、
- LinearLayout 线性布局
- RelativeLayout 相对布局
1.LinearLayout 线性布局
1.1 怎么将Android Studio默认的ConstrantLayout改为LinearLayout
1. 在design页面下->component tree->ConstrainLayout右键->Convert view...->选择LinearLayout 点击apply
1. 在code页面下->直接修改代码 将 androidx.constraintlayout.widget.ConstraintLayout 改为 LinearLayout
1.2 线性布局有两种:
1 .2.1如果没有android:orientation属性的存在
android:orientation="horizontal"
1.2.2垂直的线性布局 所有控件都是垂直挨个排布
android:orientation="vertical"
注意
tips: 在android中,所有在页面上显示的东西,必须具备两个属性,这两个属性是宽和高
android:layout_width 宽度
Android:layout_height 高度
对于宽度和高度,他们的值有三个
1. wrap_content 按照内容自适应
1. match_parent 按照父容器尺寸填满
1. 50dp 数值(用的地方很单一)
1.3 比重
android:layout_weight
如何算总比重: 看同一父亲且同一级的各个控件的weight
一旦weight属性生效,android:layout_width失效
1.4布局排布
android:gravity 内容位置改变
android:layout_gravity 本身位置改变
1.5分割线
android:divider="@color/black"
android:showDividers="middle"
1.6嵌套线性结构
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"><LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout></LinearLayout>
2.RelativeLayout相对布局
RelativeLayout和LinearLayout类似,都是ViewGroup,能“容纳”多个子view。 RelativeLayout 是一个以相对位置显示子视图的视图组。每个视图的位置可以指定为相对于同级元素的位置(例如,在另一个视图的左侧或下方)或相对于父级 RelativeLayout 区域的位置
基本框架
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/img1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerInParent="true"
android:src="@drawable/pic1"/>
...
</RelativeLayout>
RelativeLayout 的属性
- 相对于兄弟元素
android:layout_below="@id/aaa" | 在指定View的下方 |
android:layout_above="@id/aaa" | 在指定View的上方 |
android:layout_toLeftOf="@id/aaa" | 在指定View的左边 |
android:layout_toRightOf="@id/aaa" | 在指定View的右边 |
android:layout_alignTop="@id/aaa" | 与指定View的上边界一致 |
android:layout_alignBottom="@id/aaa" | 与指定View下边界一致 |
android:layout_alignLeft="@id/aaa" | 与指定View的左边界一致 |
android:layout_alignRight="@id/aaa" | 与指定View的右边界一致 |
- 相对于父元素
android:layout_alignParentLeft="true" | 在父元素内左边 |
android:layout_alignParentRight="true" | 在父元素内右边 |
android:layout_alignParentTop="true" | 在父元素内顶部 |
android:layout_alignParentBottom="true" | 在父元素内底部 |
- 对齐方式
android:layout_centerInParent="true" | 居中布局 |
android:layout_centerVertical="true" | 垂直居中布局 |
android:layout_centerHorizontal="true" | 水平居中布局 |
- 间隔
android:layout_marginBottom="" | 离某元素底边缘的距离 |
android:layout_marginLeft="" | 离某元素左边缘的距离 |
android:layout_marginRight ="" | 离某元素右边缘的距离 |
android:layout_marginTop="" | 离某元素上边缘的距离 |
android:layout_paddingBottom="" | 往内部元素底边缘填充距离 |
android:layout_paddingLeft="" | 往内部元素左边缘填充距离 |
android:layout_paddingRight ="" | 往内部元素右边缘填充距离 |
android:layout_paddingTop="" | 往内部元素右边缘填充距离 |
边栏推荐
猜你喜欢
随机推荐
Postgresql 快照
【Matlab仿真】:一带电量为q的电荷以速度v运动,求运动电荷产生磁感应强度
flink onTimer定时器实现定时需求
解决JDBC在web工程中无法获取配置文件
flink自定义轮询分区产生的问题
浏览器中的同源策略
完美解决keyby造成的数据倾斜导致吞吐量降低的问题
thymeleaf中onclick事件动态传递参数问题
with recursive用法
对象存储-分布式文件系统-MinIO-1:概念
多个gcc/glibc版本的共存及指定gcc版本的编译
ES6 Const Let Var的区别
ISCC2021———MISC部分复现(练武)
个人练习三剑客基础之模仿CSDN首页
[NSSRound#1 Basic]
CTFshow—Web入门—信息(1-8)
程序员的财富观
超详细MySQL总结
Kubernetes基础入门(完整版)
实际开发中左菜单自定义图标点击切换