I have a layout with CoordinatorLayout, AppBarLayout and RecyclerView as below.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:background="#aaa"
tools:context="com.elyeproj.recycleranimation.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="256dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/cheese_2"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/myRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#aaa"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
It works fine where the AppBarLayout could shrink as the RecyclerView scroll as shown in GIF below. It won't scroll beyond row 100.
When the list is short, it is not scrollable, since the RecyclerView is wrap-content, as shown below
However, when the list is not too short, but not longer than the page height, the scrolling went beyond the row "100", and display some empty space as below.
My question is, for scenario 3, is it possible to have a way to prevent over-scroll, i.e. the scrowing happens until row 100 only, and the AppBarLayout still visible partly as above?
RecyclerView basically is a list of items from the data. RecyclerView is often referred to as a successor of GridView and ListView. More about RecyclerView could be found at RecyclerView in Android with Example. RecyclerView lets the users scroll up and down and left and right by setting appropriate orientation via attributes.
When clicking each image, a Snackbar will pop up from the screen bottom. When the RecyclerView scrolls, you can see the collapsing toolbar expanded and collapsed. The floating action button is anchored at the RecyclerView component bottom end corner.
Generally, CollapsingToolbarLayout contains two child components, one is ImageView the other is Toolbar. 1. Android Collapsing Toolbar Example Overview. In this example, there is a Toolbar wrapped by CollapsingToolbarLayout. The CollapsingToolbarLayout is used as a direct child of AppBarLayout. And AppBarLayout is child of CoordinatorLayout.
Every RecyclerView list is constructed from three primary elements : Visual Elements, which consists of the RecyclerView widget itself and the content layout that will give visual structure to the RecyclerView’s contents. This content layout will be programmatically connected to the RecyclerView widget using the Adapter class.
Try RecyclerView height to match_parent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With