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

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

xml文件:

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

posted @   jetz  阅读(3970)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
历史上的今天:
2010-07-24 异步方式访问网页
2008-07-24 VB显示真彩图标
2007-07-24 如何清除应用程序承载 WebBrowser 控件时缓存
2005-07-24 最近读的文章
点击右上角即可分享
微信分享提示