Tuesday, September 6, 2011

[android-developers] Horizontal scrolling in grid view

I had to use a horizontal scrolling as well as vertical scrolling in
my activity and I searched a lot on this but found no post that
addresses this problem. I don't know why Google has not provided a
resolution to this yet as this is absolutely needed feature one will
want in his data driven application. I have tried using the following
solution which helped me achieve this functionality. Hope it helps and
benefit others too.

The horizontalscrollview enables you to scroll horizontally and the
gridview enables vertical scrolling.

P.S.: This is working for Android tablets(api level 12). I don't know
if horizontalscrollview is supported by 2.x SDK

<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is a long string. Hope this doesn't fit
the layout and goes beyond the width of the layout.This is a long
string. Hope this doesn't fit the layout and goes beyond the width of
the layout.This is a long string. Hope this doesn't fit the layout and
goes beyond the width of the layout.This is a long string. Hope this
doesn't fit the layout and goes beyond the width of the layout." />
<GridView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="20dp"
android:verticalSpacing="20dp"
android:horizontalSpacing="50dp"
android:numColumns="10"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"/>
</LinearLayout>
</HorizontalScrollView>

~Rikki

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment