当前位置:网站首页>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 |
边栏推荐
猜你喜欢
随机推荐
剑指 Offer 2022/7/1
剑指 Offer 2022/7/11
Androd Day02
(五)栈及其应用
WARNING: sql version 9.2, server version 11.0.Some psql features might not work.
字典特征提取,文本特征提取。
多项式回归(PolynomialFeatures)
Redis持久化方式RDB和AOF详解
简单说Q-Q图;stats.probplot(QQ图)
(十三)二叉排序树
BUUCTF——MISC(一)
什么是跨域和同源
(十五)B-Tree树(B-树)与B+树
将两个DataTable合并——DataTable.Merge 方法
ES6 Const Let Var的区别
【深度学习21天学习挑战赛】3、使用自制数据集——卷积神经网络(CNN)天气识别
JS实现上一个、下一个、置顶、置底操作
SQl练习 2022/6/29
flink-sql自定义函数
攻防世界MISC———Dift