当前位置:网站首页>Androd Day02
Androd Day02
2022-08-04 06:04: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.6Nested Linear Structures
<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="" | Padding distance to the bottom edge of the inner element |
android:layout_paddingLeft="" | Padding distance to the left edge of the inner element |
android:layout_paddingRight ="" | Padding distance to the right edge of the inner element |
android:layout_paddingTop="" | Padding distance to the right edge of the inner element |
边栏推荐
- 【深度学习21天学习挑战赛】2、复杂样本分类识别——卷积神经网络(CNN)服装图像分类
- MySQL最左前缀原则【我看懂了hh】
- JS实现上一个、下一个、置顶、置底操作
- TensorFlow2学习笔记:8、tf.keras实现线性回归,Income数据集:受教育年限与收入数据集
- 网络大作业心得笔记
- 安装dlib踩坑记录,报错:WARNING: pip is configured with locations that require TLS/SSL
- 攻防世界MISC———Dift
- SQL练习 2022/7/4
- Kubernetes基础入门(完整版)
- Matplotlib中的fill_between;np.argsort()函数
猜你喜欢
随机推荐
浏览器中的同源策略
剑指 Offer 2022/7/1
自动化运维工具Ansible(3)PlayBook
sklearn中的pipeline机制
ISCC2021———MISC部分复现(练武)
JS深复制对象方法(深拷贝)
MySQL事务详解(事务隔离级别、实现、MVCC、幻读问题)
剑指 Offer 20226/30
postgresql中创建新用户等各种命令
进程、线程、协程的区别和联系?
(TensorFlow)——tf.variable_scope和tf.name_scope详解
二月、三月校招面试复盘总结(二)
关系型数据库-MySQL:约束管理、索引管理、键管理语句
npm install dependency error npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND
【深度学习21天学习挑战赛】2、复杂样本分类识别——卷积神经网络(CNN)服装图像分类
Kubernetes基本入门-集群资源(二)
Kubernetes基础入门(完整版)
Commons Collections1
flink on yarn任务迁移
自动化运维工具Ansible(2)ad-hoc