user12330913
user12330913

Reputation: 27

Children of relative layour order not working

I use relative layout in xml and use two child for layout

But my second child not placed in front

How I can fix z-index?

My code:

<RelativeLayout
        android:id="@+id/lnrShowList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="false"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="250dp"
        android:layout_marginBottom="50dp"
        android:clickable="true"
        android:gravity="center"
        android:visibility="visible"
        android:layout_alignParentEnd="true">

        <carbon.widget.LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="false"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="15dp"
            android:layout_marginRight="20dp"
            android:layout_marginBottom="20dp"
            android:background="@color/colorBgWhite"
            android:clickable="false"
            android:gravity="center"
            android:orientation="vertical"
            app:carbon_cornerRadius="16dp"
            app:carbon_elevation="@dimen/elevation"
            app:carbon_elevationShadowColor="@color/colorShadow">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:fontFamily="@font/sahel_font"
                android:gravity="right"
                android:text="مشاهده لیست همه نتایج یافت شده"
                android:textColor="#787878"
                android:textSize="11dp" />

        </carbon.widget.LinearLayout>

        <LinearLayout
            android:id="@+id/arrowGo"
            android:layout_width="100dp"
            android:layout_height="30dp"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true"
            android:background="@drawable/showlist_bg_gray"
            android:gravity="center"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="22dp"
                android:layout_height="22dp"
                android:layout_gravity="center"
                android:adjustViewBounds="false"
                android:background="@drawable/up" />
        </LinearLayout>

    </RelativeLayout>

In other layout z-index with element work fine, but for this xml not work

Even I change relative layout to constraint layout but not work!

This problem when show I use carbon Screen:

enter image description here

Upvotes: 0

Views: 41

Answers (2)

Md. Asaduzzaman
Md. Asaduzzaman

Reputation: 15423

To achieve this you have to set more elevation in your 2nd child layout of RelativeLayout. For Example

Set elevation to 10dp in your carbon.widget.LinearLayout

app:carbon_elevation="10dp"

And set elevation to 11dp in your LinearLayout

app:elevation="11dp"

Upvotes: 1

Lukas
Lukas

Reputation: 839

There are two ways how to solve this.

  1. yourView.bringToFront(); This brings your arrowGo layout in front using java.
  2. change the ordering of your layouts, so that the arrowGo is above the LinearLayout

Upvotes: 1

Related Questions