How can I make my layout scroll both horizontally and vertically?

I am using TableLayout. I need to have horizontal and vertical scrolling for this layout. By default, I can get vertical scroll in the view, but horizontal scroll does not work.

I am using Android SDK 1.5 r3. I already tried android:scrollbars="horizontal" .

I read on some forums that horizontal scrolling is possible in updating cupcakes.

How can I scroll the layout in both directions?

+55
android android-widget android-scrollview
Sep 09 '09 at 13:11
source share
4 answers

I managed to find a simple way to achieve how to scroll behavior.

Here is the xml for it:

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="vertical"> <HorizontalScrollView android:layout_width="320px" android:layout_height="fill_parent"> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linlay" android:layout_width="320px" android:layout_height="fill_parent" android:stretchColumns="1" android:background="#000000"/> </HorizontalScrollView> </ScrollView> 
+129
Sep 11 '09 at 8:09
source share
β€” -

Too late, but I hope this code quickly solves your problem. nothing else to do, just put your code at the bottom of the scroll.

 <HorizontalScrollView android:id="@+id/scrollView" android:layout_width="wrap_content" android:layout_height="match_parent"> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> //xml code </ScrollView> </HorizontalScrollView> 
+5
Dec 07 '16 at 12:07 on
source share

In this Scrollview post vertically and horizontally on an android, they talk about a possible solution, quoting:

Matt Clark created his own view based on the Android source and it seems to work fine: http://blog.gorges.us/2010/06/android-two-dimensional-scrollview

Remember that the class on this page has an error calculating the horizontal width of the view. Manuel Hilti's fix in the comments:

Decision. Replace the statement on line 808 with the following text:

 final int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.leftMargin + lp.rightMargin, MeasureSpec.UNSPECIFIED); 
+1
Apr 19 '11 at 18:23
source share

Use this:

 android:scrollbarAlwaysDrawHorizontalTrack="true" 

Example:

 <Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbarAlwaysDrawHorizontalTrack="true" /> 
0
Oct. 20 '11 at 12:44
source share



All Articles