我想像whatsapp一样构建消息布局。我有一个edittext和一个recylerView。
问题是键盘出现时隐藏了消息!
所以,让我们说这是RecylerView:
---item 1---
---item 2---
---item 3---
---item 4---
---EditText---
当键盘出现时,我明白了:
---item 1---
---item 2---
---EditText---
---Keyboard---
但我想得到这个:
---item 3---
---item 4---
---EditText---
---Keyboard---
注意:当我设置 linearLayoutManager.setStackFromEnd(true);
它有效但当有一条消息出现在页面底部时。
使用recyclerview和editText为活动设置adjustresize:
android:windowSoftInputMode="adjustResize"
将onLayoutChangeListener添加到RecyclerView并在onLayoutChange中将scrollToPosition设置为data.size() - 1:
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)
{
mRecyclerView.scrollToPosition(mMessages.size()-1);
}
});
我这样做的方法是根据项目持有者的大小设置setStackFromEnd(),并在androidManifest中设置adjustResize。
这是我检查的方式:
if (recycleView.getChildCount() == items.size()){
mLayoutManager.setStackFromEnd(true);
}
else{
mLayoutManager.setStackFromEnd(false);
}
我不擅长英语。
使用ChatRecyclerView并将linearlayoutmanager的stackfromend设置为false。
public class ChatRecyclerView extends RecyclerView {
private int oldHeight;
public ChatRecyclerView(Context context) {
super(context);
}
public ChatRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ChatRecyclerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
int delta = b - t - this.oldHeight;
this.oldHeight = b - t;
if (delta < 0) {
this.scrollBy(0, -delta);
}
}
}
我得到了解决方案 单击编辑文本时推送内容
把代码放在下面
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);