讓你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);
你試過'recyclerView .smoothScrollToPosition(位置)'? – jlively
它不起作用。我的recyclerview在nestedscrollview中。 –
你有沒有找到答案? – praj