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
RecyclerView
in your layout and chances are there you have kept it inLinearLayout
which is again part ofCollapsingToolbarLayout
. I have absolutely no idea why you have keptRecyclerView
as part ofCollapsingToolbarLayout
. I will give a layout (simplified one) which I am using.FrameLayout
with idheader_frame
is responsible for big toolbar which will collapse on scrolling.Toolbar
with idmain_toolbar
is responsible for collapsed view of toolbar.RecyclerView
is the belowAppBarLayout
.ImageView
is for back button that will be displayed once collapsedToolbar
is displayed.For reference, to make scroll smooth I have added
CustomRecyclerScrollBehavior
which I talked earlier with you. This is what it isThis class is used for maintaining scroll speed for
RecyclerView
in nested scrolls. It's fling has been changed over hereHope this works out for you!