Android 布局优于更多线性布局

标签 android android-layout

我想像图片一样创建布局

3个绿色布局为线性布局,代码如下。 有人可以给我这三个绿色上其他红色布局的代码吗?应该是什么类型的布局?

enter image description here

    <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">


        <LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:layout_weight="1">

            </LinearLayout>
        <LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:layout_weight="1">

            </LinearLayout>
        <LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:layout_weight="1">

            </LinearLayout>

 </LinearLayout>

谢谢

最佳答案

您想将所有重叠布局放入相对布局中。因此,要重新创建与您的图片类似的内容,请执行以下操作:

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

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#00ff00"
            android:layout_marginRight="10dp" >
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#00ff00"
            android:layout_marginRight="10dp" >
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#00ff00"
            android:layout_marginRight="10dp" >
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:background="#ff0000"
            android:orientation="vertical"
            android:layout_marginTop="200dp" 
            android:layout_marginRight="50dp">
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:background="#ff0000"
            android:orientation="vertical"
            android:layout_marginTop="200dp" 
            android:layout_marginRight="50dp">
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

关于Android 布局优于更多线性布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8423787/

相关文章:

Android:在当前位置将文本插入EditText

android - 在 Oculus GO 触摸板上滑动会触发不应有的 UI 点击

Java for 循环永不终止

Android单选按钮文字加粗

android - 将滑动标签与工具栏一起使用

android - android 上有 dex 创建器吗?

android - java.lang.NoClassDefFoundError $$inlined$forEach$lambda$1 在 Kotlin

android - 将对象属性分配给 ListView

android - EditText 中的 "word-wrap: break-word"

android - 如何为 TabHost 背景动态更改 shapedrawable 颜色?