How to use HorizontalScrollView?

Go To StackoverFlow.com

0

I want my app to be able to scroll horizontally so it can slide between pages. But when I use this feature on android sdk it won't let me make the xml layout fill parent i.e. it won't let me have a full screen to include my buttons and objects.

Any idea on how can I fix this or what is an alternate method?

Here's the code:

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:layout_width="348dp"
        android:layout_height="559dp" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="341dp"
            android:layout_marginLeft="146dp"
            android:src="@drawable/ic_launcher" />

    </RelativeLayout>


</HorizontalScrollView>
2012-04-05 02:41
by user1144349
It would be nice if you can add your cod - Mark Pazon 2012-04-05 02:48
Yes here i added the code^ - user1144349 2012-04-05 02:54
Possible duplicate of stackoverflow.com/questions/556594 - Robert Harvey 2012-04-06 17:31


0

Change the relative layout to LinearLayout. Similar to a vertical ScrollView, it makes use of a LinearLayout.

Here is a sample layout I have in one of my projects:

<HorizontalScrollView
            android:id="@+id/horizontalScrollView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scrollbars="none" >

            <LinearLayout
                android:id="@+id/LinearLayout1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal" >

                <Button
                     android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/class_tab" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/exam" />

                <Button
                    android:id="@+id/button_more"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/more" />

            </LinearLayout>
        </HorizontalScrollView>
2012-04-05 02:48
by Mark Pazon
Cool, but where are all the layout attribute for the buttons and everything - user1144349 2012-04-05 02:53
oh I added them in the style attribute. let me change it - Mark Pazon 2012-04-05 02:55
Cool! and how does this work? If i test it what happends exactly - user1144349 2012-04-05 03:02
Do you mean that you want to flip between different pages instead of scrolling horizintally similar to what a vertical scrollview is doing? Scrolling and flipping are two different things. If you want flipping to pages then I think you should check out ViewPager - Mark Pazon 2012-04-05 03:17
i want it to slide as if it were a long horizontal page. But flipping sounds cooler i will def checkViewPage - user1144349 2012-04-05 11:20
Ads