Android scrollview onScrollChanged

前端 未结 11 1390
不思量自难忘°
不思量自难忘° 2020-12-08 20:36

I have a fixed content in my text view inside a scroll view. When the user scrolls to a certain position, I would like to start an activity or trigger a Toast.<

11条回答
  •  清歌不尽
    2020-12-08 21:01

    I extended my scrollView. This link may help.

    class MyScroll extends ScrollView {
        boolean onTop=true;
        @Override
        protected void onScrollChanged(int l, int t, int oldl, int oldt) {
            //Log.d(TAG, "scroll changed: " + this.getTop() + " "+t);
            if(t <= 0){
                onTop = true;
                //Log.d(TAG, "scroll top: " + t);
                super.onScrollChanged(l, t, oldl, oldt);
                return;
                // reaches the top end
            }
            onTop = false;
    
            View view = (View) getChildAt(getChildCount()-1);
            int diff = (view.getBottom()-(getHeight()+getScrollY()+view.getTop()));// Calculate the scrolldiff
            if( diff <= 0 ){
                // if diff is zero, then the bottom has been reached
            }
            super.onScrollChanged(l, t, oldl, oldt);
        }
    }
    

提交回复
热议问题