android的5种布局小析其二

接上。

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"

        android:gravity="center_horizontal|center_vertical"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"

            >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@color/colorAccent"
                android:text="this is a"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_gravity="right"
                android:gravity="right"
                android:background="@color/colorPrimary"

                android:text="this is b"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="this is a"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"

                android:text="this is b"/>

        </LinearLayout>

    </LinearLayout>



@3 第三种布局是RelativeLayout布局。这种布局可以通过设置其视图的

layout_above 上面

layout_below 下面

layout_toLeftOf 左面

layout_toRightOf 右面

可以组合设置成左上,左下等。需要设置每个视图的id。

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
            android:id="@+id/tv1"
        android:text="this is a "/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tv2"
            android:layout_toRightOf="@id/tv1"
            android:layout_below="@id/tv1"
            android:text="this is b"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tv3"
            android:layout_toRightOf="@id/tv2"
            android:layout_above="@id/tv2"
            android:text="this is c"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tv4"
            android:layout_below="@id/tv2"
            android:layout_toLeftOf="@id/tv2"
            android:text="this is d"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tv5"
            android:layout_toRightOf="@id/tv2"
            android:layout_below="@id/tv2"
            android:text="this is e"/>


    </RelativeLayout>

@第4种布局是表格布局。其视图控件中的layout_span属性用来指定占用了几列。

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TableRow>
        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="this is a "/>

        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="this is b"/>
        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="this is c"/>
        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="this is d"/>

    </TableRow>
    <TableRow>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="this is a "/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="this is b"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="this is c"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="this is d"/>

    </TableRow>

    <TableRow>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="this is a "/>


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_span="3"
            android:background="@color/colorPrimary"
            android:text="this is c"/>


    </TableRow>

</TableLayout>

其中第3行 第2个元素占用了3列的空间。



@第5种布局是AbsoluteLayout布局。名为绝对布局。通过

layout_x和layout_y属性设置坐标值。

    <AbsoluteLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="this is absolutelayout"
            android:layout_x="100dp"
            android:layout_y="100dp"
            />
    </AbsoluteLayout>





猜你喜欢

转载自blog.csdn.net/mengtianwxs/article/details/79040304