I have a layout where I have a NestedScrollView containing an Image, multiple buttons and a RecycleView.
When I say recycleView.smoothScrollToPosition or recycleView.scrollToPosition() it doesn't do anything at the moment. Refuse to scroll even a pixel. If I remove the NestedScrollView it works fine, but in case I lose the scrolling effect on the surrounding areas.
Does any of you met with this problem before?
<?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:fitsSystemWindows="true"
tools:context="world.the.rule.com.testtollbarstuff.ScrollingActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="none"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_collapseMode="parallax">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/mock_image" />
<include layout="@layout/content_scrolling" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CollapsingToolbarLayout>
If you just want smooth scroll then no custom scrolling required as I mentioned earlier in some other thread.
Add lines as below when ever you want to start smooth scroll
Additional Info
Additionally, I don't see any
RecyclerViewin your layout and chances are there you have kept it inLinearLayoutwhich is again part ofCollapsingToolbarLayout. I have absolutely no idea why you have keptRecyclerViewas part ofCollapsingToolbarLayout. I will give a layout (simplified one) which I am using.FrameLayoutwith idheader_frameis responsible for big toolbar which will collapse on scrolling.Toolbarwith idmain_toolbaris responsible for collapsed view of toolbar.RecyclerViewis the belowAppBarLayout.ImageViewis for back button that will be displayed once collapsedToolbaris displayed.For reference, to make scroll smooth I have added
CustomRecyclerScrollBehaviorwhich I talked earlier with you. This is what it isThis class is used for maintaining scroll speed for
RecyclerViewin nested scrolls. It's fling has been changed over hereHope this works out for you!