Samsung Galaxy S2 2.3.5+ not calling overScrollBy()

十年热恋 提交于 2019-12-21 04:22:09

问题


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

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

    protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY,int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent)
    {
     ...
     return super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, 0, metrics.widthPixels,isTouchEvent);
    }

On every other device (Gingerbread and up of course), overScrollBy is being called when the scroller reaches it's end, and the user can actually overscroll the view).

On Android 2.3.5+ Samsung have Implemented some kind of mechanism that disables overscroll completely (not just their overscroll implementation, but also Android's implementation), and every time a user tries to overscroll, the following LogCat event is being printed:

02-13 16:02:34.230: D/BounceScrollRunnableDefault(15783): run(), TimeFraction=0.5225, mBounceExtent=7.273352

Is there any way to unlock what Samsung did there? Or maybe another way to create an overscroller?


回答1:


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;
        }
    });



回答2:


Problem solved, I have created my own OverScrollView, you are welcome to use it. https://github.com/EverythingMe/OverScrollView



来源:https://stackoverflow.com/questions/9261911/samsung-galaxy-s2-2-3-5-not-calling-overscrollby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!