Samsung Galaxy S2 2.3.5+ not calling overScrollBy()

后端 未结 2 962
情深已故
情深已故 2021-02-15 13:59

Seems like Samsung disabled their overscroll (probably due to an Apple suit).

I have an implementation of a view that extends ScrollView and overrides

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-15 14:23

    I just faced the same problem and finally came up with the following custom overscroll detection:

        listView.setOnTouchListener(new OnTouchListener() {
    
            private static final float OVERSCROLL_THRESHOLD_IN_PIXELS = 70;
    
            private float downY;
    
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int firstVisibleItem = listView.getFirstVisiblePosition();
                int totalItemCount = listView.getCount();
                int visibleItemCount = listView.getChildCount();
                boolean onTop = firstVisibleItem == 0 && listView.getChildAt(0) != null && listView.getChildAt(0).getTop() == 0;
                boolean onBottom = firstVisibleItem + visibleItemCount == totalItemCount && listView.getChildAt(visibleItemCount-1).getBottom() == listView.getHeight();
    
                if(onTop || onBottom) {
                    switch(event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        downY = event.getY();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        float deltaY = event.getY() - downY;
                        if(onTop && deltaY > OVERSCROLL_THRESHOLD_IN_PIXELS) {
                            // Top overscroll
                        }
                        if(onBottom && -deltaY > OVERSCROLL_THRESHOLD_IN_PIXELS) {
                            // Bottom overscroll
                        }
                        break;
                    }
                }
    
                return false;
            }
        });
    

提交回复
热议问题