码迷,mamicode.com
首页 > 其他好文 > 详细

相对布局和网格布局

时间:2016-04-20 23:29:31      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

技术分享

技术分享
<?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:text="按钮"
        android:layout_alignParentLeft="true"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮"
        android:layout_alignParentRight="true"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮"
        android:layout_centerInParent="true"
        android:id="@+id/bt_center"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮"
        android:layout_centerHorizontal="true"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮"
        android:layout_centerVertical="true"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="新按钮"
        android:layout_alignBottom="@id/bt_center"
        android:layout_toLeftOf="@id/bt_center"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="新按钮"
        android:layout_alignTop="@id/bt_center"
        android:layout_toRightOf="@id/bt_center"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="新按钮"
        android:layout_above="@id/bt_center"
        android:layout_alignLeft="@id/bt_center"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="新按钮"
        android:layout_below="@id/bt_center"
        android:layout_alignRight="@id/bt_center"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="新按钮"
        android:layout_below="@id/bt_center"
        android:layout_toLeftOf="@id/bt_center"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="新按钮"
        android:layout_below="@id/bt_center"
        android:layout_toRightOf="@id/bt_center"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="新按钮"
        android:layout_above="@id/bt_center"
        android:layout_toRightOf="@id/bt_center"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="新按钮"
        android:layout_above="@id/bt_center"
        android:layout_toLeftOf="@id/bt_center"/>

</RelativeLayout>
View Code

技术分享

技术分享
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:rowCount="3"
    android:columnCount="4"
    android:padding="10dp">

    <Button
        android:text="按钮1"
        android:layout_row="0"
        android:layout_column="1"
        android:layout_columnSpan="1"
        android:layout_gravity="fill"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"/>
    <Button
        android:text="按钮2"
        android:layout_row="0"
        android:layout_column="0"
        android:layout_rowSpan="1"
        android:layout_gravity="fill"
        android:layout_columnWeight="1"/>
    <Button
        android:layout_gravity="fill"
        android:text="按钮3"
        android:layout_columnWeight="1"/>
    <Button
        android:layout_gravity="fill"
        android:text="按钮4"
        android:layout_columnWeight="1"/>
    <Button
        android:layout_gravity="fill"
        android:text="按钮5"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"/>
    <Button
        android:layout_gravity="fill"
        android:text="按钮6"
        android:layout_columnWeight="1"/>
    <Button
        android:layout_gravity="fill"
        android:text="按钮7"
        android:layout_columnWeight="1"/>
    <Button
        android:layout_gravity="fill"
        android:text="按钮8"
        android:layout_columnWeight="1"/>

</GridLayout>
View Code

技术分享

 

相对布局和网格布局

标签:

原文地址:http://www.cnblogs.com/bilibiliganbei/p/5414638.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!