Android随笔

解决RecycleView 与EditText焦点问题导致Rec

2018-10-22  本文已影响0人  爱玩单机的人

以下展示主要的代码,其它不相关内容省略,如果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;
       }
 });

.
.
.
上一篇 下一篇

猜你喜欢

热点阅读