android 学习 之 布局(下)LinearLayout,RelativeLayout,TableLayout,FrameLayout

本文深入探讨了Android应用中使用线性布局、相对布局、表格布局、帧布局等不同布局方式,并详细介绍了按钮、按钮组、相对位置布局、表格布局及帧布局的用法与实现。

 

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFCC"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.rhythmk.app.MainActivity$PlaceholderFragment" >

    <!--
           wap_content :包裹实际文本宽度, match_parent: 铺满父类容器, fill_parent:铺满父类容器




    -->

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="按钮1" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="按钮2" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="按钮3" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#CCCC66"
        android:orientation="horizontal" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮01" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮02" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮03" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#99CC66"
        android:orientation="horizontal" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮11" />

        <Button
            android:id="@+id/btn12"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="150sp"
            android:layout_marginTop="50sp"
            android:text="按钮12" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="60sp"
            android:layout_marginTop="50sp"
            android:layout_toRightOf="@+id/btn12"
            android:text="按钮13" />
    </RelativeLayout>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#9933CC"
        android:shrinkColumns="1"
        android:stretchColumns="0,1,2" >

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="独立行" />

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="按钮21" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="按钮22" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="按钮22" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="按钮31" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_column="2"
                android:text="我可以自动延生" />
        </TableRow>
    </TableLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#0033CC"
        android:padding="20px" >

        <Button
            android:layout_width="250px"
            android:layout_height="150px"
            android:background="#330033"
            android:text="FrameLayout001" />

        <Button
            android:layout_width="250px"
            android:layout_height="150px"
            android:layout_marginLeft="100sp"
            android:layout_marginTop="80sp"
            android:background="#990066"
            android:text="FrameLayout002" />
    </FrameLayout>

</LinearLayout>

 

转载于:https://www.cnblogs.com/rhythmK/p/4058197.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值