一、引言
? ? ? 如何合理安排控件的位置,使得界面整潔美觀?就需要使用布局管理器來實現(xiàn)
二、教學(xué)內(nèi)容
1. AbsoluteLayout
? ? ? ? ? ? ? 絕對布局,控件的位置由坐標(biāo)決定。
? ? ? ? ? ? ? 因為屏幕大小和分辨率的不同,此布局不推薦。
? ? ? ? ? ? ? layout_x。layout_y,原點在左上角
2. LinearLayout
? ? ? ? ? ? ?線性布局,所有控件按照某個方向依次擺放
????????????只有一行或者一列
????????????orientation? 設(shè)定列或行方向 vertical 垂直 horizontal 水平
????????????layout_gravity 控件在父容器中的位置
????????????gravity 文字內(nèi)容在控件中的位置
3. FrameLayout
????????????幀布局,控件疊加擺放,以左上角為原點
4.TableLayout
? ? ? ? ? ? 表格布局,設(shè)定若干行,控件放在行內(nèi)
? ? ? ? ? ? TableRow 行
????????????layout_weight? 指定一行內(nèi)控件占據(jù)寬度的比重
5. RelativeLayout
? ? ? ? ? ? 相對布局,最常用的布局,特點是控件的位置由參照物決定
? ? ? ? ? ? 1)參照物為父容器
? ? ? ? ? ? ? ? layout_centerHorizontal 水平居中
????????????????layout_centerVertical 垂直居中
????????????????layout_centerInParent 父容器內(nèi)中間
? ? ? ? ? ? ? ? layout_alignParent***? 設(shè)定對齊方式
? ? ? ? ? ? 2)參照物為其他容器
? ? ? ? ? ? ? ? layout_to***of? 在其他控件的左邊或右邊
? ? ? ? ? ? ? ? layout_above/below? 在其他控件的上下
? ? ? ? ? ? ? ? layout_align***? 和其他控件的對齊方式
? ? ? ? ? ? ? ? layout_margin***:和其他控件的間隔,外邊距
? ? ? ? ? ? ? ? padding***? 控件或者容器的內(nèi)邊距
設(shè)計登錄界面
?<Button?
? ? ? ? android:id="@+id/resetButton"
????????android:layout_centerVertical="true"?
? ? ? ? andriod:layout_centerHorizontal="true"
? ? ? ? android:text="重置"/>
<Button
????????android:id="@+id/loginButton"
? ? ????android:layout_toleftof="@id/resetButton"
? ??????android:layout_marginEnd="20dp"
????????android:alignTop="true"
????????android:text="登錄"/>
<Button
? ? ? ? android:id="@+id/cancelButton"
? ? ????android:layout_torighttof="@id/resetButton"
????????android:layout_marginStart="20dp"
????????android:alignTop="true"
????????android:text="取消"/>
6.ConstraintLayout
? ? ? ? ? ? 約束布局,默認(rèn)布局,非常強(qiáng)大靈活,