以下展示主要的代碼,其它不相關(guān)內(nèi)容省略,如果RecyclerView 中有多個EditText恩商,則每個EditText都設(shè)置以下監(jiān)聽即可。
private RecyclerView mRv;
private EditText mEt;
/**
* RecyclerView是否可以垂直滑動
*/
private boolean mRvCanScrollVertically = false;
.
.
.
// 設(shè)置RecyclerView LayoutManager愉适,這里以LinearLayoutManager 垂直滑動為例酸役,其它LayoutManager與這個一樣,覆寫canScrollVertically即可
mRv.setLayoutManager(new LinearLayoutManager(mContext) {
@Override
public boolean canScrollVertically() {
return mRvCanScrollVertically;
}
});
// 給RecyclerView設(shè)置touch監(jiān)聽
mRv.setOnTouchListener((v, event) -> {
mRvCanScrollVertically = true;
return false;
});
mEtSearch.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus) {
mRvCanScrollVertically = false;
}
});
.
.
.