【问题标题】:Recyclerview scrollToPosition doesn't work with NestedScrollView ? Is there anyway?Recyclerview scrollToPosition 不适用于 NestedScrollView ?到底有没有?
【发布时间】:2017-07-19 12:14:03
【问题描述】:

所以我在NestedScrollView 中有一个Recyclerview。当我说recycleview.scrollToPosition(X)recycleview.getLayoutManager().scrollToPosition(X) 时,它根本不起作用。

如果我将recycleviewnestedScrollView 中移出,它可以正常工作,但我不能这样做,因为布局结构!有什么想法吗?

scrollingView.requestChildFocus(recyclerView,recyclerView);

试过了,但没有专注于某个位置

【问题讨论】:

  • 你试过recyclerView.smoothScrollToPosition(position)吗?
  • 它不起作用。我的 recyclerview 在 nestedscrollview 内。
  • 你找到答案了吗?
  • stackoverflow.com/a/50604638/6798 看看这个解决方案。

标签: android android-recyclerview android-scrollview android-nestedscrollview nestedscrollview


【解决方案1】:

像这样制作你的回收站视图

<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>

和java代码

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);

【讨论】:

  • 它不起作用。我的 recyclerview 在 nestedscrollview 内。
  • 您是否将 setNestedScrollingEnabled(false) 设置为您的回收站视图
  • @BincyBaby 尝试最后一个选项
  • 它在我的情况下不起作用。我每次都将 z 的值设为“0”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-20
  • 2018-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-05
相关资源
最近更新 更多