0

So I have this android app, where the menu has a lot of buttons. I have put scroll so for phones with smaller screen, they need to scroll down to see all the buttons, but for phones with big screen, there is no need to scroll as all the buttons will be visible.

I need to alert the users who need to use scroll down using a dialog or something, but need do anything for those who need not scroll.

Is this even possible?

Nikhil
  • 2,168
  • 6
  • 33
  • 51
  • Just check the size of the child of the `ScrollView` against the screen available space and determine if the user needs to scroll. But putting a `Dialog` might be too much, if you keep the scrollbars on the `ScrollView` that is a sufficient indication that there is more of that menu than what the user currently sees. – user Dec 08 '12 at 11:41
  • Generally, just putting `scrollbars` on a `ScrollView` is sufficient. They get shorter as the view gets taller, and will be the length of the screen when scrolling isn't needed. The only reason you'd check the view height against the screen window is if you wanted the scrollbars to disappear if scrolling wasn't needed (unless that's already built in. I can't think of it on the top of my head). – DeeV Dec 08 '12 at 12:35

1 Answers1

-1
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {  
                    int scrollRange = scrollView
                                .computeVerticalScrollRange();
                    if(scrollRange>screenHeight){
                     //user need to scroll
                     }



                    }
                });
Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77
  • If only the `computeVerticalScrollRange()` method would be available just like that. – user Dec 08 '12 at 12:22
  • 1
    `ScrollView.computeVerticalScrollRange()` is a **protected** method, so you would need a subclass to make it accessible from the `OnGlobalLayoutListener` – nicopico May 06 '13 at 15:49