onClick method not working properly after NestedScrollView scrolled

前端 未结 7 965
梦毁少年i
梦毁少年i 2020-11-30 23:13

I used NestedScrollView with CoordinatorLayout to enable scroll animation for Toolbar (by app:layout_scrollFlags=\"scroll|enterAlways\").

NestedScrollView contain th

7条回答
  •  天命终不由人
    2020-11-30 23:26

    It is a Bug mention at Google #issues 194398.

    Just need to use this WorkaroundNestedScrollView.java class which extends NestedScrollView like,

    WorkaroundNestedScrollView.java

    public class WorkaroundNestedScrollView extends NestedScrollView {
    
    public WorkaroundNestedScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            // Explicitly call computeScroll() to make the Scroller compute itself
            computeScroll();
        }
        return super.onInterceptTouchEvent(ev);
    }
    }
    

    And in yourlayout use it like this,

    layout.xml

    
    ...
    ...
    
    
    

    You can alson find more details here.

提交回复
热议问题