新思想

Android布局

一、LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        >
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#ff0000"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#ffffff"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#0000ff"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="@android:color/darker_gray"
            />
    </LinearLayout>

    <LinearLayout
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        >
        <TextView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="#00ff00"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="#000000"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="#ff0"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="#ff00ff"
            />
    </LinearLayout>
</LinearLayout>

 

二、RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <Button
        android:id="@+id/center"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:text="中间"
        android:layout_centerInParent="true"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="上面"
        android:layout_above="@id/center"
        android:layout_alignLeft="@id/center"
        android:layout_alignRight="@id/center"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="下面"
        android:layout_below="@id/center"
        android:layout_alignLeft="@id/center"
        android:layout_alignRight="@id/center"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="左边"
        android:layout_toLeftOf="@id/center"
        android:layout_alignTop="@id/center"
        android:layout_alignBottom="@id/center"
        android:layout_alignParentLeft="true"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="右边"
        android:layout_toRightOf="@id/center"
        android:layout_alignTop="@id/center"
        android:layout_alignBottom="@id/center"
        android:layout_alignParentRight="true"
        />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="左上"
        android:layout_toLeftOf="@id/center"
        android:layout_above="@id/center"
        android:layout_alignParentLeft="true"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="左下"
        android:layout_toLeftOf="@id/center"
        android:layout_below="@id/center"
        android:layout_alignParentLeft="true"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="右上"
        android:layout_toRightOf="@id/center"
        android:layout_above="@id/center"
        android:layout_alignParentRight="true"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="右下"
        android:layout_toRightOf="@id/center"
        android:layout_below="@id/center"
        android:layout_alignParentRight="true"
        />
</RelativeLayout>

 

三、TableLayout

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:stretchColumns="0,3">

    <TableRow>
        <TextView
            android:layout_weight="2"
            android:text="昨天"
            android:width="0dp"
            android:background="#00ffff"
            />
        <TextView
            android:layout_weight="3"
            android:text="今天"
            android:width="0dp"
            android:background="#ff00ff"
            />
        <TextView
            android:layout_weight="1"
            android:text="明天"
            android:width="0dp"
            android:background="#ffff00"
            />
    </TableRow>

    <TableRow>
        <TextView
            android:layout_weight="1"
            android:text="aaa"
            android:textAlignment="textEnd"
            android:width="0dp"
            android:background="#bfbf00"
            />
        <TextView
            android:layout_weight="2"
            android:text="bbb"
            android:textAlignment="textEnd"
            android:width="0dp"
            android:background="#bf00bf"
            />
        <TextView
            android:layout_weight="3"
            android:text="ccc"
            android:textAlignment="viewEnd"
            android:width="0dp"
            android:background="#00bfbf"
            />
        <TextView
            android:layout_weight="2"
            android:text="ddd"
            android:textAlignment="viewEnd"
            android:width="0dp"
            android:background="#bfbfbf"
            />
    </TableRow>

    <TableRow>
        <TextView />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="用户名:"/>
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="150dp"/>
        <TextView />
    </TableRow>

    <TableRow>
        <TextView />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密  码:"
            />
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="150dp"
            />
        <TextView />
    </TableRow>

    <TableRow>
        <TextView />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登陆"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="退出"/>
        <TextView />
    </TableRow>

</TableLayout>

 

四、GridLayout

GridLayout

 

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:columnCount="4" android:rowCount="6">

    <TextView
        android:layout_columnSpan="4"
        android:layout_gravity="fill"
        android:background="#E0E0E0"
        android:text="0"
        android:textAlignment="textEnd"
        android:textSize="38sp" />

    <Button android:text="C" />
    <Button android:text="DEL" />
    <Button android:text="÷" />
    <Button android:text="X" />

    <Button android:text="7" />
    <Button android:text="8" />
    <Button android:text="9" />
    <Button android:text="-" />

    <Button android:text="4" />
    <Button android:text="5" />
    <Button android:text="6" />
    <Button android:text="+" />

    <Button android:text="1" />
    <Button android:text="2" />
    <Button android:text="3" />

    <Button
        android:layout_rowSpan="2"
        android:layout_gravity="fill"
        android:text="="/>

    <Button android:text="0" />
    <Button android:text="." />
    <Button android:text="+/-" />

</GridLayout>

 

 

五、FrameLayout

FrameLayout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <TextView
        android:layout_width="350dp"
        android:layout_height="350dp"
        android:background="#ff0000"
        android:layout_gravity="center"
        />
    <TextView
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:background="#cccccc"
        android:layout_gravity="center"
        />
    <TextView
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:background="#0000ff"
        android:layout_gravity="center"
        />
    <TextView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#ffff00"
        android:layout_gravity="center"
        />
    <TextView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:background="#00ff00"
        android:layout_gravity="center"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#8000EE"
        android:layout_gravity="center"
        />
</FrameLayout>

源程序下载

posted on 2016-05-02 11:47  新思想  阅读(704)  评论(0)    收藏  举报

导航