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

橙三吉。 提交于 2019-12-05 12:13:58

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!