简体   繁体   中英

Relative layout hidden behind Recycler view

I am trying to put my progress screen ( @+id/progressScreen ) on top of my recycler view ( @+id/cardList ) but for some reason the recycler view always comes on top and hides it. I've tried View.bringToFront() but it doesn't work

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:background="@drawable/gradient"
    tools:showIn="@layout/activity_main"
    android:id="@+id/root_layout"
    tools:targetApi="LOLLIPOP">

    <RelativeLayout
        android:elevation="5dp"
        android:id="@+id/relativeToolbar"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="?attr/colorPrimary" />

    <RelativeLayout
        android:elevation="5dp"
        android:layout_marginRight="12dp"
        android:layout_marginLeft="12dp"
        android:layout_alignParentTop="true"
        android:layout_width="match_parent"
        android:background="@color/white"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:elevation="3dp"
            android:id="@+id/cardList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal|top" />

        <com.google.android.gms.common.SignInButton
            android:id="@+id/sign_in_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:visibility="gone"
             >

        </com.google.android.gms.common.SignInButton>

        <RelativeLayout
            android:id="@+id/progressScreen"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#30FFFFFF"
            android:visibility="visible">

            <TextView
                android:id="@+id/progressText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/progressbar"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="67dp"
                />

            <ProgressBar
                android:id="@+id/progressbar"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"/>
        </RelativeLayout>

    </RelativeLayout>



</RelativeLayout>

Sorry .I read it wrong. You should first put your RelativeLayout for android:id="@+id/progressView" on top of the RecyclerView and then add android:translationZ param to correct Z index because you are using 3dp elevation for the RV. Therefore, to be on top of the RecyclerView android:translationZ="4"

Here is the fixed code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:background="@drawable/gradient"
    tools:showIn="@layout/activity_main"
    android:id="@+id/root_layout"
    tools:targetApi="LOLLIPOP">

    <RelativeLayout
        android:elevation="5dp"
        android:id="@+id/relativeToolbar"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="?attr/colorPrimary" />

    <RelativeLayout
        android:elevation="5dp"
        android:layout_marginRight="12dp"
        android:layout_marginLeft="12dp"
        android:layout_alignParentTop="true"
        android:layout_width="match_parent"
        android:background="@color/white"
        android:layout_height="match_parent">


        <RelativeLayout
            android:id="@+id/progressScreen"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"**
            android:translationZ="4dp"
            android:background="#30FFFFFF"
            android:visibility="visible">

            <TextView
                android:id="@+id/progressText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/progressbar"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="67dp"
                />

            <ProgressBar
                android:id="@+id/progressbar"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"/>
        </RelativeLayout>

        <android.support.v7.widget.RecyclerView
            android:elevation="3dp"
            android:id="@+id/cardList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal|top" />

        <com.google.android.gms.common.SignInButton
            android:id="@+id/sign_in_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:visibility="gone"
            >

        </com.google.android.gms.common.SignInButton>


    </RelativeLayout>



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