Android: Recycler 视图没有滚动到最后一个位置

Android: Recycler view is not scrolling to last position

我正在尝试使用 Recycler 视图创建聊天屏幕。由于聊天,当用户进入屏幕时,列表应该滚动到最后一个位置。

我的问题是当键盘打开列表时隐藏。 如果我们使用 adjust pan,整个视图将会向上,我试图只滚动列表,我希望当键盘打开时标题栏保持相同的位置

将此添加到您的代码中并检查....它对我来说很好....

mRecyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
{
    @Override
    public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) 
    {
        if (mRecyclerAdapter != null) 
        {
            if (bottom < oldBottom) 
            {
                mRecyclerView.smoothScrollToPosition(mRecyclerAdapter.getItemCount() - 1);
            }
        }
    }
});

收到新消息时添加此行....

mRecyclerView.smoothScrollToPosition(mRecyclerAdapter.getItemCount() - 1);

无需在清单中添加 android:windowSoftInputMode。只需将回收站视图保持在底部视图上方即可。希望这会有所帮助。`

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            </RelativeLayout>
             <RelativeLayout
                android:id="@+id/rlBottom"
                android:layout_width="match_parent"
                android:layout_height="46dp"
                android:layout_gravity="bottom"
                android:layout_margin="@dimen/dimen_8"
                android:background="@drawable/shape_write_msg"
                android:elevation="@dimen/dimen_2">

                <EditText
                    android:id="@+id/etMessage"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginEnd="@dimen/dimen_12"
                    android:layout_marginStart="@dimen/dimen_12"
                    android:layout_toEndOf="@+id/ivAdd"
                    android:layout_toStartOf="@+id/ivSend"
                    android:background="@color/white"
                    android:focusable="true"
                    android:hint="@string/label_type_here"
                    android:inputType="textCapSentences"
                    android:textColor="@color/black"
                    android:textCursorDrawable="@null"
                    android:textSize="@dimen/sp_12"
                    android:visibility="visible" />


                <ImageView
                    android:id="@+id/ivSend"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"
                    android:layout_marginEnd="@dimen/dimen_4"
                    android:padding="@dimen/dimen_8"
                    android:src="@drawable/drawable_send"
                    android:visibility="visible" />
            </RelativeLayout>
        </android.support.v7.widget.CardView>
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

`