如何将2个布局彼此叠加 [英] how to put 2 layouts on top of each others

查看:106
本文介绍了如何将2个布局彼此叠加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将2个布局相互叠加,但是它不起作用.有一个我不知道如何删除的空间.

I'm trying to put 2 layouts on top of each others but it doesn't work.There is a space that i don't know how to remove.

这是我的代码:

<LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical" 
                android:layout_gravity="bottom|center"
                android:weightSum="1">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="170dp"
                    android:layout_weight="0.5"
                    android:background="@drawable/column_white"
                    android:layout_gravity="bottom|center"
                    android:gravity="bottom"
                    android:orientation="vertical"

                    >
                    <LinearLayout 
                        android:layout_width="10sp"
                        android:layout_height="100sp"
                        android:background="@drawable/arrow_body"
                        android:layout_marginLeft="10sp"
                        ></LinearLayout>
                    <LinearLayout 
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:background="@drawable/arrow_shape"
                        android:layout_marginLeft="6sp"
                        ></LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="150dp"
                    android:layout_margin="25sp"
                    android:background="@drawable/column_blue"
                    android:gravity="center"
                    android:layout_weight="0.5" >

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="40 000 "
                        android:textColor="#ffffff"
                        android:textSize="25sp" />
                </LinearLayout>

            </LinearLayout>

RelativeLayout:

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="170dp"
        android:background="@drawable/column_white"
        android:gravity="bottom"

        android:layout_alignBottom="@id/second_part"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="10sp"
            android:layout_height="100sp"
            android:layout_marginLeft="10sp"
            android:background="@drawable/arrow_body" >
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="6sp"
            android:background="@drawable/arrow_shape" >
        </LinearLayout>

    </LinearLayout>

    <LinearLayout

        android:id="@+id/second_part"
        android:layout_width="wrap_content"
        android:layout_height="150dp"
        android:layout_margin="25sp"

        android:background="@drawable/column_blue"
        android:gravity="center" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="40 000"
            android:textColor="#ffffff"
            android:textSize="25sp" />
    </LinearLayout>
</RelativeLayout>

推荐答案

使用相对"布局将视图彼此叠加,就像这样

Use Relative layout to place views on top of each other , like this

 <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center"
        android:background="#f00"
        android:orientation="vertical"
        android:weightSum="1" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="170dp"
            android:layout_centerInParent="true"
            android:layout_gravity="bottom|center"
            android:background="#fff"
            android:gravity="bottom"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="10dp"
                android:layout_height="100sp"
                android:layout_centerInParent="true"
                android:layout_marginLeft="10sp"
                android:background="#37c100" >
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="6sp"
                android:background="@drawable/arrow_shape" >
            </LinearLayout>
        </RelativeLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="150dp"
            android:layout_centerInParent="true"
            android:layout_margin="25sp"
            android:layout_weight="0.5"
            android:background="#0000ff"
            android:gravity="center" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="40 000 "
                android:textColor="#ffffff"
                android:textSize="25sp" />
        </LinearLayout>
    </RelativeLayout>

这篇关于如何将2个布局彼此叠加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆