I have layout like this:
<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_height="match_parent"
android:layout_width="match_parent"
android:background="@color/main_gray"
tools:context=".ui.MainActivity">
<LinearLayout
android:id="@+id/firstlinear"
android:layout_width="match_parent"
android:layout_height="188dp"
android:background="@drawable/shapeformaintopbar"
android:orientation="horizontal"
android:paddingTop="10dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="@null"
android:scaleType="fitCenter"
android:src="@drawable/settings" />
<TextView
android:id="@+id/titleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:layout_weight="3"
android:fontFamily="@font/roboto_medium"
android:gravity="center"
android:text="@string/aura"
android:textColor="@color/white"
android:textSize="24sp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="@null"
android:scaleType="fitCenter"
android:src="@drawable/search" />
</LinearLayout>
<LinearLayout
android:id="@+id/categLinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/firstlinear"
android:layout_marginTop="-60dp"
android:orientation="horizontal"
android:paddingStart="6dp"
android:paddingEnd="6dp">
<androidx.cardview.widget.CardView
android:id="@+id/inboxCard"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginStart="6dp"
android:layout_marginEnd="6dp"
android:layout_weight="1"
android:clickable="true"
android:onClick="onClick"
app:cardElevation="0dp"
android:foreground="?android:attr/selectableItemBackground"
android:focusable="true">
<ImageView
android:id="@+id/inboxImg"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="18dp"
android:scaleType="fitCenter"
android:src="@drawable/dialog" />
<TextView
android:id="@+id/InboxText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="10dp"
android:fontFamily="@font/roboto_regular"
android:textColor="@color/topbartextcolor"
android:text="@string/inbox"
android:textSize="16sp" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/friendsCard"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginStart="6dp"
android:layout_marginEnd="6dp"
android:layout_weight="1"
android:onClick="onClick"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
app:cardElevation="0dp"
android:focusable="true">
<ImageView
android:id="@+id/FriendsImg"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="18dp"
android:scaleType="fitCenter"
android:src="@drawable/friends" />
<TextView
android:id="@+id/FriendsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="10dp"
android:fontFamily="@font/roboto_regular"
android:textColor="@color/topbartextcolor"
android:text="@string/friends"
android:textSize="16sp" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/profileCard"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginStart="6dp"
android:layout_marginEnd="6dp"
android:foreground="?android:attr/selectableItemBackground"
android:layout_weight="1"
android:onClick="onClick"
android:clickable="true"
app:cardElevation="0dp"
android:focusable="true">
<ImageView
android:id="@+id/ProfileImg"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="18dp"
android:scaleType="fitCenter"
android:src="@drawable/profile" />
<TextView
android:id="@+id/ProfileText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="10dp"
android:fontFamily="@font/roboto_regular"
android:textColor="@color/topbartextcolor"
android:text="@string/profile"
android:textSize="16sp" />
</androidx.cardview.widget.CardView>
</LinearLayout>
<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/categLinear"
android:layout_marginTop="15dp"
tools:listitem="@layout/inboxrecycler" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/categLinear"
android:background="@color/main_gray"
android:indeterminate="true"
android:indeterminateTint="@color/purple"
android:padding="140dp"
android:visibility="visible" />
</RelativeLayout>
And it looks like this :
There is a fragment inside the FrameLayout and recyclerview inside that fragment. So I want to collapse theese three cardviews to a tab layout when I scroll and reappear cardviews when I scroll to top, but I am not that good at material design. How may I do that?
Okay I found the solution. BIG THANKS to CTSN
I found it on github. Link: https://github.com/CTSN/TestCollapsingToolbarLayout