android第一行代码笔记5-布局
2020-06-17 本文已影响0人
刚刚8888
- LinearLayout : 线性布局
orientation:方向 vertical/horizontal
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
注意,如果 LinearLayout 的排列方向是 horizontal,内部的控件就绝对不能将 宽度指定为 match_parent,因为这样的话单独一个控件就会将整个水平方向占满,其他的控 件就没有可放置的位置了。同样的道理,如果 LinearLayout 的排列方向是 vertical,内部的控 件就不能将高度指定为 match_parent。
// 设置组件位置
android:layout_gravity="center"
// 设置组件相对大小
android:layout_weight="1"
- RelativeLayout :相对布局
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</RelativeLayout>
// 组件常用属性
// 相对于父布局
android:layout_alignParentLeft="true"、
android:layout_alignParentTop="true"、
android:layout_alignParentRight="true"、
android:layout_alignParentBottom="true"、
android:layout_centerInParent="true"
// 相对组件
android:layout_above="@id/button3"
android:layout_toLeftOf="@id/button3"
android:layout_toRightOf="@id/button3"
android:layout_below="@id/button3"
android:layout_alignLeft
android:layout_alignRight
android:layout_alignTop
android:layout_ alignBottom
- FrameLayout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</FrameLayout >
- TableLayout 表格布局
< TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:text="Account:" />
<EditText
android:id="@+id/account"
android:layout_height="wrap_content"
android:hint="Input your account" />
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:text="Password:" />
<EditText
android:id="@+id/password"
android:layout_height="wrap_content"
android:inputType="textPassword" />
</TableRow>
</TableLayout >
android:stretchColumns 的值指定为 1,表示如果表格不能完全占满屏幕宽度
继承关系图
