Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recyclerview scrollToPosition doesn't work with NestedScrollView ? Is there anyway?

Tags:

So I have a Recyclerview within a NestedScrollView. When I say recycleview.scrollToPosition(X) or recycleview.getLayoutManager().scrollToPosition(X) it doesn't work at all.

If I move the recycleview out from the nestedScrollView it works fine, but I can't do it, because of the layout structure! Any idea?

scrollingView.requestChildFocus(recyclerView,recyclerView);

tried this, but not focusing on a certain position

like image 339
Bincy Baby Avatar asked Jul 19 '17 12:07

Bincy Baby


1 Answers

make your recyclerview like this

<LinearLayout
      android:id="@+id/ll2"
      android:focusableInTouchMode="true"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

          <android.support.v7.widget.RecyclerView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_margin="5dp"
              android:clipToPadding="false"
              android:visibility="visible"/>

</LinearLayout>

and the java code

ItemsArrayList.add(0, items5);
adapter.notifyDataSetChanged();
ViewCompat.setNestedScrollingEnabled(recyclerView,false);
NestedScrollView nestedScrollingView = (NestedScrollView) findViewById(R.id.nestedScrollingView);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll2);
float y = fcRecyclerView.getChildAt(0).getY();
float z =linearLayout.getY();
nestedScrollingView.smoothScrollTo(0, (int) z);
like image 114
AskNilesh Avatar answered Oct 11 '22 12:10

AskNilesh