1. Android的基础布局
LinearLayout 线性布局
RelativeLayout 相对布局
TableLayout 表格布局
FrameLayout 帧布局(框架布局)
ConstrantLayout 约束布局 (Android Studio默认布局) 用于拖拽的
2. LinearLayout 线性布局
2.1 怎么将Android Studio默认的ConstrantLayout改为LinearLayout
1. 在design页面下--->component tree--->ConstrainLayout右键--->Convert view...--->选择LinearLayout 点击Apply (第一种方法,不推荐) 2. 在code页面下--->直接修改代码 将 androidx.constraintlayout.widget.ConstraintLayout 改为 LinearLayout (第二种方法,推荐)
2.2 线性布局有两种:
-
水平的线性布局 所有控件都是水平挨个排布
如果没有android:orientation属性的存在
或者
android:orientation="horizontal"
-
垂直的线性布局 所有控件都是垂直挨个排布
android:orientation="vertical"
tips: 在android中,所有在页面上显示的东西,必须具备两个属性,这两个属性是宽和高
android:layout_width 宽度
Android:layout_height 高度
对于宽度和高度,他们的值有三个
1. wrap_content 按照内容自适应 1. match_parent 按照父容器尺寸填满 1. 50dp 数值(用的地方很单一)
2.3 比重:
android:layout_weight
如何算总比重: 看同一父亲且同一级的各个控件的weight
一旦weight属性生效,android:layout_width失效
2.4 布局排布:
android:gravity 内容位置改变 android:layout_gravity 本身位置改变
2.5 分隔线:内部的线
android:divider="@color/black" android:showDividers="middle"
2.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>
3. RelativeLayout
RelativeLayout 又称相对布局。 从名称上可以看出,这种布局方式是以一种让组件以相对于容器或者相对于容器中的另一个组件的相对位置进行放置的布