知乎专栏 |
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.cardview.widget.CardView android:layout_width="wrap_content" android:layout_height="wrap_content" app:cardCornerRadius="10dp" app:cardElevation="0dp" tools:ignore="MissingConstraints"> <ImageView android:id="@+id/imageView7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitXY" app:srcCompat="@drawable/bg_repast_menu" /> </androidx.cardview.widget.CardView> </androidx.constraintlayout.widget.ConstraintLayout>
linearLayoutManager = new LinearLayoutManager(ContextHolder.getContext()); linearLayoutManager.setStackFromEnd(true); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.scrollToPosition(adapter.getItemCount() - 1);
调用下面函数
recyclerView.smoothScrollToPosition(adapter.getItemCount() - 1);
其他用法
// linearLayoutManager.scrollToPositionWithOffset(adapter.getItemCount() - 1, Integer.MIN_VALUE); // linearLayoutManager.scrollToPosition(adapter.getItemCount() - 1);