前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android新手之旅(10) 嵌套布局

Android新手之旅(10) 嵌套布局

作者头像
用户1075292
发布2018-01-23 14:48:18
1.3K0
发布2018-01-23 14:48:18
举报
文章被收录于专栏:听雨堂听雨堂

想在界面上放四个按钮,以2*2的形式存在,却没有办法快速实现。尝试了一下,可以用嵌套的方式,一个LinearLayout嵌套两个LinearLayout,外层的LinearLayout用纵向布局,而内部的用横向布局 xml文件:

代码语言:js
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bk0">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="180px"
        android:layout_marginLeft="60px" android:layout_marginTop="70px"
        >
        <Button android:background="@drawable/btn01" 
            android:text="" android:id="@+id/button1" 
            android:layout_width="wrap_content" android:layout_height="wrap_content" 
            >
        </Button>
        <Button android:background="@drawable/btn02" 
            android:text="" android:id="@+id/button2" 
            android:layout_width="wrap_content" android:layout_height="wrap_content" 
            >
        </Button>
    </LinearLayout>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="180px"
        android:layout_marginLeft="60px" android:layout_marginTop="0px"
        >
        <Button android:background="@drawable/btn03" 
            android:text="" android:id="@+id/button3" 
            android:layout_width="wrap_content" android:layout_height="wrap_content" 
            >
        </Button>
        <Button android:background="@drawable/btn04" 
            android:text="" android:id="@+id/button4" 
            android:layout_width="wrap_content" android:layout_height="wrap_content" 
            >
        </Button>
    </LinearLayout>
</LinearLayout>

效果:

image
image
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2011-07-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档