Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can AppBarLayout with RecyclerView works without letting RecyclerView over-scroll?

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.

enter image description here

When the list is short, it is not scrollable, since the RecyclerView is wrap-content, as shown below

enter image description here

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.

enter image description here

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?

like image 968
Elye Avatar asked Dec 09 '16 12:12

Elye


People also ask

What is the use of recyclerview in Android?

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.

How to use snackbar in recyclerview?

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.

What is collapsingtoolbarlayout in Android?

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.

How is a recyclerview list constructed?

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.


1 Answers

Try RecyclerView height to match_parent.

like image 162
inhogo Avatar answered Oct 14 '22 12:10

inhogo