Get maximum HorizontalScrollView scroll amount

后端 未结 1 1201
青春惊慌失措
青春惊慌失措 2020-12-18 03:06

I\'m adding floating arrows to my HorizontalScrollView which will let the user know that there are more item\'s outside of the current view.

What I need

相关标签:
1条回答
  • 2020-12-18 03:46

    The child of the horizontal scrollview should have the correct width. Try this

    Log.e("ScrollWidth",Integer.toString(horizontalScrollview.getChildAt(0).getMeasuredWidth()-
            getWindowManager().getDefaultDisplay().getWidth()));
    

    This should be the max scroll amount.

    Put the following code in your onCreate method

    ViewTreeObserver vto = scrollView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            scrollView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            Log.e("ScrollWidth",Integer.toString(horizontalScrollview.getChildAt(0)
                    .getMeasuredWidth()-getWindowManager().getDefaultDisplay().getWidth()));
    
        }
    });
    
    0 讨论(0)
提交回复
热议问题