Skip to main content
added 4 characters in body
Source Link
Steve Benett
  • 12.9k
  • 7
  • 62
  • 81

You can do some little math to calculate the views raw height and the height of the content. If the difference of this heights is < 0 the view is scrollable.

To calculate the raw height you can use View.getMeasuredHeight(). Because ScrollView is a ViewGroup and has max one child, get the height of that child with ViewGroup.getChildAt(0).getHeight();

Use a ViewTreeObserver to get the heights, because it will be called at the moment the layout / view is changing the visibility, otherwise the heights could be 0.

ScrollView scrollView = (ScrollView)findViewById(R.id...); ViewTreeObserver observer = scrollView.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int viewHeight = scrollView.getMeasuredHeight(); int contentHeight = scrollView.getChildgetChildAt(0).getHeight(); if(viewHeight - contentHeight < 0) { // scrollable } } }); 

You can do some little math to calculate the views raw height and the height of the content. If the difference of this heights is < 0 the view is scrollable.

To calculate the raw height you can use View.getMeasuredHeight(). Because ScrollView is a ViewGroup and has max one child, get the height of that child with ViewGroup.getChildAt(0).getHeight();

Use a ViewTreeObserver to get the heights, because it will be called at the moment the layout / view is changing the visibility, otherwise the heights could be 0.

ScrollView scrollView = (ScrollView)findViewById(R.id...); ViewTreeObserver observer = scrollView.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int viewHeight = scrollView.getMeasuredHeight(); int contentHeight = scrollView.getChild(0).getHeight(); if(viewHeight - contentHeight < 0) { // scrollable } } } 

You can do some little math to calculate the views raw height and the height of the content. If the difference of this heights is < 0 the view is scrollable.

To calculate the raw height you can use View.getMeasuredHeight(). Because ScrollView is a ViewGroup and has max one child, get the height of that child with ViewGroup.getChildAt(0).getHeight();

Use a ViewTreeObserver to get the heights, because it will be called at the moment the layout / view is changing the visibility, otherwise the heights could be 0.

ScrollView scrollView = (ScrollView)findViewById(R.id...); ViewTreeObserver observer = scrollView.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int viewHeight = scrollView.getMeasuredHeight(); int contentHeight = scrollView.getChildAt(0).getHeight(); if(viewHeight - contentHeight < 0) { // scrollable } } }); 
added 2 characters in body
Source Link
Steve Benett
  • 12.9k
  • 7
  • 62
  • 81

You can do some little math to calculate the views raw height and the height of the content. If the difference of this heights is < 0 the view is scrollable.

To calculate the raw height you can use View.getMeasuredHeight(). Because ScrollView is a ViewGroup and has max one child, get the height of that child with ViewGroup.getChildAt(0).getHeight();

Use a ViewTreeObserver to get the heights, because it will be called at the moment the layout / view is changing the visibility, otherwise the heights cancould be 0.

ScrollView scrollView = (ScrollView)findViewById(R.id...); ViewTreeObserver observer = scrollView.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int viewHeight = scrollView.getMeasuredHeight(); int contentHeight = scrollView.getChild(0).getHeight(); if(viewHeight - contentHeight < 0) { // scrollable } } } 

You can do some little math to calculate the views raw height and the height of the content. If the difference of this heights is < 0 the view is scrollable.

To calculate the raw height you can use View.getMeasuredHeight(). Because ScrollView is a ViewGroup and has max one child, get the height of that child with ViewGroup.getChildAt(0).getHeight();

Use a ViewTreeObserver to get the heights, because it will be called at the moment the layout / view is changing the visibility, otherwise the heights can be 0.

ScrollView scrollView = (ScrollView)findViewById(R.id...); ViewTreeObserver observer = scrollView.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int viewHeight = scrollView.getMeasuredHeight(); int contentHeight = scrollView.getChild(0).getHeight(); if(viewHeight - contentHeight < 0) { // scrollable } } } 

You can do some little math to calculate the views raw height and the height of the content. If the difference of this heights is < 0 the view is scrollable.

To calculate the raw height you can use View.getMeasuredHeight(). Because ScrollView is a ViewGroup and has max one child, get the height of that child with ViewGroup.getChildAt(0).getHeight();

Use a ViewTreeObserver to get the heights, because it will be called at the moment the layout / view is changing the visibility, otherwise the heights could be 0.

ScrollView scrollView = (ScrollView)findViewById(R.id...); ViewTreeObserver observer = scrollView.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int viewHeight = scrollView.getMeasuredHeight(); int contentHeight = scrollView.getChild(0).getHeight(); if(viewHeight - contentHeight < 0) { // scrollable } } } 
Source Link
Steve Benett
  • 12.9k
  • 7
  • 62
  • 81

You can do some little math to calculate the views raw height and the height of the content. If the difference of this heights is < 0 the view is scrollable.

To calculate the raw height you can use View.getMeasuredHeight(). Because ScrollView is a ViewGroup and has max one child, get the height of that child with ViewGroup.getChildAt(0).getHeight();

Use a ViewTreeObserver to get the heights, because it will be called at the moment the layout / view is changing the visibility, otherwise the heights can be 0.

ScrollView scrollView = (ScrollView)findViewById(R.id...); ViewTreeObserver observer = scrollView.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int viewHeight = scrollView.getMeasuredHeight(); int contentHeight = scrollView.getChild(0).getHeight(); if(viewHeight - contentHeight < 0) { // scrollable } } }