3 五大布局

来源:互联网 发布:sql distinct 多个字段 编辑:程序博客网 时间:2024/06/09 21:22

<?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:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="直拳" />


    <Button
        android:id="@+id/btn_left_quan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="左勾拳" />


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@id/btn_left_quan"
        android:layout_alignParentRight="true"
        android:text="右摆拳" />


    <Button
        android:id="@+id/btn_dajuezhao"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="大绝招, 必杀技" />


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="逃跑神器" />


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/btn_dajuezhao"
        android:layout_alignLeft="@id/btn_dajuezhao"
        android:layout_marginBottom="100px"
        android:padding="100px"
        android:text="前进" />


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/btn_dajuezhao"
        android:layout_toRightOf="@id/btn_dajuezhao"
        android:layout_marginLeft="20px"
        android:text="向右" />


</RelativeLayout>



<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >  // 线性布局的排列方式


    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="right"  // 当前空间在父空间的位置
        android:gravity="right|center_vertical" // 控件中的内容 在控件中的内容
        android:text="按钮1" />


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


    <LinearLayout  // 线性布局中包含线性布局
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >


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


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="按钮2" />
    </LinearLayout>


</LinearLayout>


<?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" >


    <Button
        android:layout_width="300px"
        android:layout_height="200px"
        android:layout_gravity="center"
        android:text="底部" />


    <Button
        android:layout_width="150px"
        android:layout_height="80px"
        android:layout_gravity="center"
        android:text="中间" />


    <Button
        android:layout_width="50px"
        android:layout_height="50px"
        android:layout_gravity="center"
        android:text="顶部" />


</FrameLayout>


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


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="106dp"
        android:layout_y="232dp"
        android:text="炮弹" />


</AbsoluteLayout>


<?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:shrinkColumns="0"
    android:stretchColumns="1"
    android:collapseColumns="0" >


    <TableRow android:layout_height="wrap_content" >


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="第0列" />


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="第1列" />


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="第2列" />


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="第3列" />
    </TableRow>


    <TableRow android:layout_height="wrap_content" >


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_span="2"
            android:text="第一列" />
    </TableRow>


</TableLayout>

LinearLayout 线性布局

android:orientation="horizontal"    
制定线性布局的排列方式    
水平 horizontal    
垂直 vertical
gravity 控制当前控件内容显示区域
layout_gravity 当前控件在父元素的位置
Layout_weightSum
Layout_weight 额外空间分配(权重)


android:visibility="invisible"
控制布局是否显示
显示 visible
不显示,但占空间 invisible
隐藏 gone



RelativeLayout 相对布局

android:layout_toRightOf 在指定控件的右边
android:layout_toLeftOf 在指定控件的左边
android:layout_above 在指定控件的上边
android:layout_below 在指定控件的下边
android:layout_alignBaseline 跟指定控件水平对齐
android:layout_alignLeft 跟指定控件左对齐
android:layout_alignRight 跟指定控件右对齐
android:layout_alignTop 跟指定控件顶部对齐
android:layout_alignBottom 跟指定控件底部对齐
android:layout_alignParentLeft 是否跟父布局左对齐
android:layout_alignParentTop 是否跟父布局顶部对齐
android:layout_alignParentRight 是否跟父布局右对齐
android:layout_alignParentBottom 是否跟父布局底部对
android:layout_centerVertical 在父布局中垂直居中
android:layout_centerHorizontal 在父布局中水平居中
android:layout_centerInParent 在父布局中居中


AbsoluteLayout 绝对布局/FrameLayout 帧布局



AbsoluteLayout
android:layout_x 指定控件在父布局的x轴坐标
android:layout_y 指定控件在父布局的y轴坐标


FrameLayout
帧布局每次添加的控件都显示在最上面,最后显示在界面上的是最后添加的一个控件

TableRow单元行里的单元格的宽度小于默认的宽度时就不起作用,其默认是fill_parent,高度可以自定义大小


TableLayout 表格布局

android:shrinkColumns 收缩列
android:stretchColumns 拉伸列
android:collapseColumns 隐藏列
android:layout_column 指定列(作用在列的身上)
android:layout_span 合并列(作用在列的身上)


0 0
原创粉丝点击