LinearLayout
線性布局,有兩個(gè)方向:垂直與水平,控件的位置控制使用weight與layout_gravity;
RelativeLayout
相對(duì)布局,使用多個(gè)相對(duì)屬性控制控件的位置,無(wú)法使用layout_gravity
TableLayout
- stretchColumns屬性指定列數(shù),從0開(kāi)始計(jì)數(shù)
- 一個(gè)控件占據(jù)一行
- 大多數(shù)屬性跟LinearLayout差不多
- 列的寬度,通過(guò)weight設(shè)置
使用<TableRow>標(biāo)簽,標(biāo)簽本身代表一列,標(biāo)簽里面的控件依次各占一列
用TableLayout實(shí)現(xiàn)賬號(hào)輸入
<TableLayout
android:id="@+i/tableUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:stretchColumns="0,1">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"http://
android:text="用戶:"
android:textSize="20dp" />
<EditText
android:id="@+id/etEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:hint="請(qǐng)輸入用戶名字" />
</TableRow>
</TableLayout>
GridLayout
有水平和垂直兩個(gè)方向;使用columnCount進(jìn)行一行有多少列的設(shè)置,使用columnSpan進(jìn)行控件的跨列設(shè)置,占據(jù)一行
使用weightColumns進(jìn)行列的權(quán)重
一些呵呵噠的屬性
- columnCount 設(shè)置一行的最大列數(shù)
- rowCount 設(shè)置最大的行數(shù)
- columnSpan 設(shè)置跨列數(shù)
- rowSpan 設(shè)置跨行數(shù)
- columnWeight 列的權(quán)重
- rowWeight 行的權(quán)重
FrameLayout
幀布局,將控件以一層層幀的形式放置在布局中,像是一疊信件
PercentRelativeLayout
更像是線性布局與相對(duì)布局的合體,使用百分比進(jìn)行控件的大小設(shè)置
一些讓人呵呵噠的屬性
- layout_widthPercent;值為百分比
- layout_heigthPercent;值為百分比
使用步驟
- 加上編譯jar包,在gradle文件中compile設(shè)置
compile 'com.android.support:percent:24.0.0' - 在布局文件中進(jìn)行app命名空間設(shè)置
xmlns:app="http://schemas.android.com/apk/res-auto"