以下展示主要的代码,其它不相关内容省略,如果RecyclerView 中有多个EditText,则每个EditText都设置以下监听即可。
private RecyclerView mRv;
private EditText mEt;
/**
* RecyclerView是否可以垂直滑动
*/
private boolean mRvCanScrollVertically = false;
.
.
.
// 设置RecyclerView LayoutManager,这里以LinearLayoutManager 垂直滑动为例,其它LayoutManager与这个一样,覆写canScrollVertically即可
mRv.setLayoutManager(new LinearLayoutManager(mContext) {
@Override
public boolean canScrollVertically() {
return mRvCanScrollVertically;
}
});
// 给RecyclerView设置touch监听
mRv.setOnTouchListener((v, event) -> {
mRvCanScrollVertically = true;
return false;
});
mEtSearch.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus) {
mRvCanScrollVertically = false;
}
});
.
.
.