Tuesday, March 20, 2012

How to scroll vertically and Horizontally in android?

This is what i have done to fix the same..

       <LinearLayout 

              xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical">                                                   

              <HorizontalScrollView                                                                         
                  android:id="@+id/horizontal_scroll_view"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:scrollbars="horizontal">
                                                                          
                  <ScrollView                                                                          
                      android:id="@+id/vertical_scroll_view"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:scrollbars="vertical">
                                                               
                      <LinearLayout                                                       

                          android:id="@+id/linear_layout"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content">

                                  <!--childrens go here..
                                          I have used an image view for demonstration-->

                      </LinearLayout>
                     
                  </ScrollView>
                 
              </HorizontalScrollView>          
        </LinearLayout>

Probably  the vertical scroll bar may not be visible at first. However once you reach the extreme end of x-axis(right), vertical scroll can be seen. If you want to see both @ a time set width & height of scrollviews  respectively
          Also you may interchange the order of the scrollviews. By doing so i found no difference. However make sure your vertical scroll view hosted by a LinearLayout(with vertical orientation) and any children should be hosted by a single LinearLayout within vertical ScrollView.

No comments:

Post a Comment