RecyclerView:禁用由于焦点更改而导致的滚动 [英] RecyclerView: Disable scrolling caused by change in focus

查看:615
本文介绍了RecyclerView:禁用由于焦点更改而导致的滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR 我的RecyclerViewEditText s.当用户将焦点放在EditText #1上并点击EditText #2时,我希望EditText #2获得焦点,但是我不想ReyclerView滚动.我该如何实现?

TL;DR I have a RecyclerView of EditTexts. When the user is focused on EditText #1 and taps on EditText #2, I want EditText #2 to get focus but I don't want the ReyclerView to scroll. How can I achieve this?

我正在尝试使用填充有一堆EditTextRecyclerView.当我专注于一个EditText并单击另一个时,RecyclerView滚动,以便第二个在屏幕顶部.我想从RecyclerView禁用此自动滚动,但是我仍然希望用户能够滚动,并且我仍然希望第二个EditText专注于此,以便用户可以开始键入.我该如何实现?

I'm trying to work with a RecyclerView populated with a bunch of EditTexts. When I'm focused on one EditText and I click on another, the RecyclerView scrolls so that the second is at the top of the screen. I want to disable this auto-scrolling from the RecyclerView, but I still want the user to be able to scroll, and I still want the second EditText to be focused on so the user can start typing. How can I achieve this?

我已经尝试了以下解决方案:

I've already tried the following solutions:

  • https://stackoverflow.com/a/8101614/4077294, but with a RecyclerView.OnItemTouchListener. I called recyclerView.requestFocusFromTouch in onInterceptTouchEvent.

  • 行为:一直滚动到被点击的EditText顶部.
  • Behavior: Scrolled to the top of the tapped EditText all the time.

通过

从任何EditText集中焦点时清除焦点

Clearing the focus from any EditText whenever it was focused on, via

editText.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, bool hasFocus) {
        if (hasFocus) {
            v.clearFocus();
        }
    }
});

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆