尝试删除这两行或将它们设置为false
layoutManager.setReverseLayout(true)
layoutManager.setStackFromEnd(true)
setStackFromEnd
方法将视图设置为显示最后一个元素,布局方向保持不变,而setReverseLayout
方法将改变Adapter添加元素的顺序。
尝试使用这些方法在键盘出现时将你的RecyclerView
和EditText
向上移动。
<activity name="YourActivity"
android:windowSoftInputMode="stateHidden|adjustResize">
//stateHidden -> keyboard is hidden when you first open the activity
//adjustResize -> this will adjust the layout resize option
...
</activity>
在AndroidManifest.xml
文件中。
将RecyclerView置于顶部。
<android.support.v7.widget.RecyclerView
android:id="@+id/messageRecyclerViewRep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/linearLayout3"
android:layout_marginLeft="36dp"
android:scrollbars="vertical" />
首先将recyclerView放在底部,随着键盘的弹出将其向上推。
<LinearLayout
android:id="@+id/recyclerContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/linearLayout3"
android:layout_above="@+id/linearLayout"
android:gravity="bottom">
<android.support.v7.widget.RecyclerView
android:id="@+id/messageRecyclerViewRep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="36dp"
android:scrollbars="vertical" />
</LinearLayout>
当键盘弹出时,将recyclerView滚动到底部,即当recyclerView的布局更改时(您可以在编辑文本处处于活动状态、聚焦、单击或类似情况下执行相同的操作。我已在recyclerView的布局更改上完成了此操作。)
recyclerView.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 (bottom < oldBottom) {
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
recyclerView.smoothScrollToPosition(mAdapter.getItemCount());
}
}, 100);
}
}
});
FirebaseRecyclerAdapter<FriendlyMessage, MessageViewHolder> mFirebaseAdapter;
。 - user8618899