Bhavin Sorathiya
Bhavin Sorathiya

Reputation: 161

Can we hide/show Relative Layout when Recycleview list is scrolling?

This is my XML Layout in which I want to Show/Hide relative layout (@+id/room_header_rl) not actiob_bar.Please any one has idea how to do it? I try using CoordinatorLayout but not get success. Thank you in advance.

My XML Layout :

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

    <include
        android:id="@+id/app_bar"
        layout="@layout/app_bar"/>

    <RelativeLayout
        android:id="@+id/room_header_rl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:padding="10dp"
        android:layout_below="@+id/app_bar"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <RelativeLayout
            android:id="@+id/room_details_rl"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/room_img"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:layout_marginRight="10dp"
                android:scaleType="centerCrop"
                android:layout_centerVertical="true"/>

            <RelativeLayout
                android:id="@+id/rooom_rl"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/room_img"
                android:layout_centerVertical="true">

                <TextView
                    android:id="@+id/roomname_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/black"
                    android:textSize="15sp"
                    android:textStyle="bold"
                    android:maxLines="2"
                    android:drawablePadding="5dp"/>

                <TextView
                    android:id="@+id/roomdate_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/black"
                    android:layout_below="@+id/roomname_tv"
                    android:layout_marginTop="10dp"/>

                <EditText
                    android:id="@+id/roommembers_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/black"
                    android:textSize="14sp"
                    android:layout_below="@+id/roomdate_tv"
                    android:focusable="false"/>

            </RelativeLayout>

        </RelativeLayout>

        <TextView
            android:id="@+id/welcome_msg_txt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:maxLines="4"
            android:padding="5dp"
            android:gravity="center"
            android:textStyle="bold"
            android:background="@color/light_gray"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_below="@+id/room_details_rl"
            android:layout_centerHorizontal="true" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginTop="5dp"
            android:background="@color/gray"
            android:layout_below="@+id/welcome_msg_txt"/>

    </RelativeLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/roomchat_rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="20dp"
        android:layout_above="@+id/divider"
        android:layout_below="@+id/room_header_rl"/>

    <View
        android:id="@+id/divider"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/gray"
        android:layout_above="@+id/entertext_rl"/>

<RelativeLayout
    android:id="@+id/entertext_rl"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">

    <EditText
        android:id="@+id/entertext_ed"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/black"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:maxLines="3"
        android:textSize="16sp"
        android:capitalize="sentences"
        android:hint="@string/entertext"
        android:layout_toLeftOf="@id/attech_btn"
        android:background="@android:color/transparent"
        android:layout_centerVertical="true"/>

    <Button
        android:id="@+id/attech_btn"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_centerVertical="true"
        android:layout_marginRight="10dp"
        android:layout_toLeftOf="@+id/send_btn"
        android:background="@drawable/attach"/>

    <Button
        android:id="@+id/send_btn"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:background="@drawable/send_btn"/>

</RelativeLayout>

I am trying https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling%28part3%29/ but it's show/hide only actionBar.

Upvotes: 2

Views: 621

Answers (1)

Boukharist
Boukharist

Reputation: 1229

did you try to hide it programatically ?

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            my_relative_layout.setVisibility(View.GONE);
        }
    });

Upvotes: 1

Related Questions