四种基本布局

2016-04-21  本文已影响67人  TTTqiu

一、LinearLayout


LinearLayout 又称作线性布局,这个布局会将它所包含的控件在线性方向上依次排列。通过 android:orientation 属性指定排列方向是 vertical(垂直)或 horizontal(水平),默认 horizontal。

允许我们使用比例的方式来指定控件的大小。注意** android:layout_weight 设为 0 **比较规范。


二、RelativeLayout


RelativeLayout 又称作相对布局,它可以通过相对定位的方式让控件出现在布局的任何位置。

android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_above="@id/button3"
android:layout_below="@id/button3"
android:layout_toLeftOf="@id/button3"
android:layout_toRightOf="@id/button3"

三、FrameLayout


FrameLayout 这种布局没有任何的定位方式,所有的控件都会摆放在布局的左上角


四、TableLayout


TableLayout 允许我们使用表格的方式来排列控件。

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    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>
    <TableRow>
        <Button
             android:id="@+id/login"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="Login" />
    </TableRow>
</TableLayout>
上一篇 下一篇

猜你喜欢

热点阅读