Android EditText's container (RecyclerView) auto scroll when EditText is Focused

后端 未结 2 1245
暗喜
暗喜 2021-01-19 12:49

I got a RecyclerView whose element contains a EditText widget.

1.currently focusing on the second EditText,the first EditText is partly showed on the screen. the fir

2条回答
  •  醉梦人生
    2021-01-19 13:21

    Actually, there is a scroll state of RecycleView that you can control like this;

    Create your own LayoutManager and override the scrollHorizontallyBylike this.

    @Override
        public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
            int nScroll = 0;
            // Do not let auto scroll 
            if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_SETTLING){
              nScroll = super.scrollHorizontallyBy(dx, recycler, state);
            } 
    }
    

    So, what is the SCROLL_STATE_SETTLING?

    The RecyclerView is currently animating to a final position while not under outside control.

提交回复
热议问题