本文介绍了Recyclerview scrollToPosition不适用于NestedScrollView吗?反正有吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我在NestedScrollView
中有一个Recyclerview
.当我说recycleview.scrollToPosition(X)
或recycleview.getLayoutManager().scrollToPosition(X)
时,它根本不起作用.
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.
如果我将recycleview
从nestedScrollView
中移出,效果很好,但由于布局结构,我做不到!有什么主意吗?
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
推荐答案
使您的recyclerview像这样
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>
和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 scrollToPosition不适用于NestedScrollView吗?反正有吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!