1

所以我有一個RecyclerviewNestedScrollView內。當我說recycleview.scrollToPosition(X)recycleview.getLayoutManager().scrollToPosition(X)它根本不起作用。Recyclerview scrollToPosition不適用於NestedScrollView?無論如何?

如果我將recycleviewnestedScrollView中移出,它工作正常,但由於佈局結構,我無法完成這項工作!任何想法?

scrollingView.requestChildFocus(recyclerView,recyclerView); 

嘗試這樣做,而不是專注於某一位置

+0

你試過'recyclerView .smoothScrollToPosition(位置)'? – jlively

+0

它不起作用。我的recyclerview在nestedscrollview中。 –

+1

你有沒有找到答案? – praj

回答

3

讓你recyclerview這樣

<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(); 
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); 
+0

它不起作用。我的recyclerview在nestedscrollview中。 –

+0

檢查更新ans –

+0

它不會工作。 –

相關問題