问题 如何在键盘出现时按下recylerView?


我想像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); 它有效但当有一条消息出现在页面底部时。


3605
2017-09-10 16:05


起源

请检查 这个 解决方法。 - Bolein95
你有没有弄明白@david? - steviemo


答案:


使用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);

}
    });

13
2018-05-26 09:05



2018年最好的简单解决方案 - Nastromo


我这样做的方法是根据项目持有者的大小设置setStackFromEnd(),并在androidManifest中设置adjustResize。

这是我检查的方式:

if (recycleView.getChildCount() == items.size()){
    mLayoutManager.setStackFromEnd(true);
}
else{
    mLayoutManager.setStackFromEnd(false);
}

2
2017-10-31 01:57





我不擅长英语。 使用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);
        }
    }
}

1
2018-04-04 14:40





我得到了解决方案 单击编辑文本时推送内容

把代码放在下面

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

0
2017-09-20 10:21



只是指着 另一个 所以问题真的不足以弥补答案。 - GhostCat