-1

I am working on an application where I'm using AppBarLayout with CollapsingToolbarLayout and NestedScrollView. I have successfully implemented this and it is working fine.

The NestedScrollView with the CollapsingToolbarLayout does not scroll smoothly. The Nestedscrollview scrolls smoothly on scroll down but on scroll up, the NestedScrollView sticks to the top. How do I create a NestedScrollView with CollapsingToolbarLayout that scrolls smoothly?

this question is not helpful. Here is my code:

<?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"
tools:context=".view.activity.ActivityShowRent"
android:theme="@style/AppThemeFullScreen"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layoutDirection="rtl"
    android:theme="@style/AppTheme.AppBarOverlay">
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:contentScrim="@color/colorPrimaryDark"

app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/show_detail_media_height"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7"
            android:id="@+id/lyt_game_info_head"
            android:fitsSystemWindows="true">
            <VideoView
                android:id="@+id/vdo_game"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentStart="true"
                android:layout_marginTop="0dp"
                android:scaleType="fitXY"
                android:fitsSystemWindows="true"
                android:layout_alignParentTop="true"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_marginBottom="30dp"/>
            <ImageView
                android:id="@+id/img_game"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentStart="true"
                android:fitsSystemWindows="true"
                android:scaleType="fitXY"
                android:src="@drawable/test"
                android:layout_alignParentTop="true"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_marginBottom="30dp"
                android:visibility="gone"/>
            <ImageView
                android:id="@+id/img_game_cover"
                android:layout_width="@dimen/item_list_games_image_width"
                android:layout_height="@dimen/item_list_games_image_height"
                android:layout_alignBottom="@+id/vdo_game"
                android:layout_alignParentEnd="true"
                android:layout_marginBottom="-30dp"
                android:layout_marginEnd="20dp"
                android:contentDescription="TODO"
                android:src="@drawable/test"/>
            <TextView
                android:id="@+id/txt_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/txt_console"
                android:layout_alignParentStart="true"
                android:padding="5dp"
                android:textStyle="bold"
                android:text="test1"
                android:textSize="@dimen/font_size_medium"
                android:textColor="@color/main_text_color"
                android:background="#8f000000"
                android:layout_margin="3dp"/>
            <TextView
                android:id="@+id/txt_console"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/txt_genres"
                android:layout_alignParentStart="true"
                android:padding="5dp"
                android:text="test2"
                android:textColor="@color/main_text_color"
                android:textSize="@dimen/font_size_small"
                android:background="#8f000000"
                android:layout_margin="3dp"/>
            <TextView
                android:id="@+id/txt_genres"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/vdo_game"
                android:layout_alignParentStart="true"
                android:background="#8f000000"
                android:padding="5dp"
                android:text="test3"
                android:layout_marginStart="3dp"
                android:textColor="@color/main_text_color"
                android:textSize="@dimen/font_size_small"/>
            <TextView
                android:id="@+id/txt_release_date"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentStart="true"
                android:padding="5dp"
                android:text="test4"
                android:textColor="@color/gray_text_color"
                android:textSize="@dimen/font_size_small"/>
        </RelativeLayout>
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_behavior=".view.ToolbarBackgroundAlphaBehavior">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">
                <LinearLayout
                    android:layout_width="0sp"
                    android:layout_height="match_parent"
                    android:layout_weight="1">
                    <TextView
                        android:id="@+id/txt_page_name"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_gravity="right"
                        android:gravity="center"
                        android:text="page name"
                        android:textColor="#ffffff"
                        android:textSize="14dp"/>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="48sp"
                    android:layout_height="48sp"
                    android:layout_gravity="center"
                    android:layout_marginRight="10sp"
                    android:gravity="center">
                    <ImageView
                        android:id="@+id/img_back"
                        android:layout_width="42dp"
                        android:layout_height="42dp"
                        android:layout_gravity="center_vertical"
                        android:background="@drawable/back_buttons_ripple_effect"
                        android:padding="10sp"
                        android:scaleType="fitCenter"
                        android:src="@drawable/ic_back"/>
                </LinearLayout>
            </LinearLayout>
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:fillViewport="true"
    android:fitsSystemWindows="true"
    android:clipToPadding="false"
    android:scrollbars="none">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@color/colorPrimary">
        <Button
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_margin="20dp"
            android:background="@drawable/back_buttons"
            android:text="play"
            android:textColor="@color/colorPrimary"
            android:textSize="@dimen/font_size_very_large"
            android:textStyle="bold"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/main_text_color"
            android:padding="5dp"
            android:text="Lorem ipsum is a pseudo-Latin text used in web 
 design, typography, layout, and printing in place of English to emphasise      
 design elements over content. It's also called placeholder (or filler) 
text.      It's a convenient tool for mock-ups. It helps to outline the 
visual elements of a document or presentation, eg typography, font, or 
layout. Lorem ipsum is mostly a part of a Latin text by the classical author 
and philosopher Cicero. Its words and letters have been changed by addition 
  or removal, so to deliberately render its content nonsensical; it's not 
 genuine, correct, or comprehensible Latin anymore. While lorem ipsum's 
 still resembles classical Latin, it actually has no meaning whatsoever. As 
  Cicero's text doesn't contain the letters K, W, or Z, alien to latin, 
these, and others are often inserted randomly to mimic the typographic 
 appearence of European languages, as are digraphs not to be found in the 
original."/>
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>
 </android.support.design.widget.CoordinatorLayout>
mf340
  • 41
  • 8
  • `NestedScrollView` inside `CollapsingToolbarLayout`? Your codes shows that it is outside of `CollapsingToolbarLayout`. Would you check and edit your question to be more clear? – ʍѳђઽ૯ท Sep 10 '18 at 16:00
  • @ʍѳђઽ૯ท thanks for reply edited – mf340 Sep 12 '18 at 06:40

2 Answers2

0

The NestedScrollView inside the CollapsingToolbarLayout does not scroll smoothly

Since it's not in the CollapsingToolbarLayout so I'm assuming that this line:

app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed"

Might cause some issues plus the added codes to NestedScrollView.

Solution: So, I'd suggest using following code inside CollapsingToolbarLayout:

app:layout_scrollFlags="scroll|exitUntilCollapsed"

Also, this piece of code for NestedScrollView:

<android.support.v4.widget.NestedScrollView
            android:id="@+id/nested_scroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

Then it should work properly.

ʍѳђઽ૯ท
  • 15,369
  • 7
  • 47
  • 103
0

I found solution.This problem has been solved by google from the support library after version 26.0.0 this was helpful

mf340
  • 41
  • 8