简体   繁体   中英

android xml - how to overlap two view

I have an image like one below,there is two view represented by dark green and green.how to make green above dark green,because as we can see part of the dark green area is covered by green?

在此处输入图像描述

and this my simple code

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_marginStart="40dp"
    android:layout_marginEnd="40dp"
    android:background="@color/dark_green">
</View>
<View
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="-100dp"
    android:background="@color/green">
</View>

Use Relativelayout as parent layout and it will work file

 <Relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:background="@color/dark_green">
</View>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-100dp"
android:background="@color/green">
 </View>
 </Relativelayout >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM