Thursday, August 13, 2009

Scrollview in Android

I never noticed, or realised how an application’s UI would render when the orientation changed, since most of the time I tested my apps on the emulator. But one fine day, when a friend of mine walked in and asked to change the orientation, I shocked to see that the layouts didn’t fit in the landscape view.
Well, the solution!!!
Wrap your layouts in a parent ScrollView, so that, when the orientation changes, you will be able to at-least scroll and view the whole layout. How the UI looks, is however a different concern.

5 comments:

  1. Hi,

    Any idea how i can provide both horizontal and vertical scrolling support to my View (say grid view or Gallery)

    Thanks & Regards,
    Abhishek

    ReplyDelete
  2. There is a property "Scrollbars" which you can set to both. I guess, that should work.

    ReplyDelete
  3. Kumar, at least LinearLayout doesn't have scrollbars. You need to wrap it inside ScrollView.

    ReplyDelete
  4. @Anonymous : All the View/Viewgroup classes have scrollbars. They will only be visible if you enable them.

    ReplyDelete
  5. @Kumar Bibek: Sorry, LinearLayout does not scroll, have you tried it successfully without a ScrollView?

    See here:
    http://groups.google.com/group/android-developers/browse_thread/thread/60bcba56bdb68fd/50f7e60de3fcd705?q=linearlayout+does+not+allow+vertical#50f7e60de3fcd705

    Here:
    http://www.anddev.org/scrolling-t4076.html

    And here:
    http://groups.google.com/group/android-developers/browse_thread/thread/5791448435a84596/f1541b608419f79c?q=linearlayout+does+scroll#f1541b608419f79c

    Att,
    Carlos Maciel

    ReplyDelete