问题描述:
我使用 RecyclerView 来做消息列表,但是在软键盘弹起时会遮挡住 RecyclerView,而不是将 RecyclerView 与输入框一起顶上去。
清单文件里的 android:windowSoftInputMode 我设置为 adjustResize没效果。试过设置为 adjustPan,但是会将 标题栏也顶出布局外面。
问:该怎样才能做到像微信那样弹出软键盘会将 RecyclerView 顶上去?
黄舟2017-04-17 18:02:17
The title bar is pushed up probably because your layout file is not written correctly. I need to know how your xml is written. In addition, it is possible that it is not blocked and the RecyclerView does not slide to the bottom.
高洛峰2017-04-17 18:02:17
For RecyclerView, you need two configurations, one is, android:windowSoftInputMode="adjustResize"
, and the other is to add this when the code initializes RecyclerView
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
//这是重点
layoutManager.setReverseLayout(true);
mRecyclerView.setLayoutManager(layoutManager);
高洛峰2017-04-17 18:02:17
AndroidManifest sets the soft keyboard state of Activity android:windowSoftInputMode="stateHidden|adjustResize"
//Set the layout manager
LinearLayoutManager mManager = new LinearLayoutManager(mContext);
mManager.setStackFromEnd(true); //Key
recyclerView.setLayoutManager(mManager);