0

in my xml style I use a android.support.v4.view.ViewPager within a ScrollView. The problem is that I dont get a scrollbar. The ViewPager itself behaves also strange when I slide from one page to another.

Setting the ScrollView to a fixed height e.g. 1200dip helps to scroll but doesnt show the ViewPager. Here is my xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fadeScrollbars="true"
    android:fillViewport="true"
    android:scrollbars="vertical" >


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



        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/menu"
            />

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </android.support.v4.view.ViewPager>
    </RelativeLayout>

</ScrollView>

thanks in advance

user1324936
  • 2,187
  • 4
  • 36
  • 49
  • http://stackoverflow.com/questions/2646028/android-horizontalscrollview-within-scrollview-touch-handling found the solution – user1324936 Aug 29 '12 at 21:10
  • 1
    Post an answer to your question and validate your own. I lost my time getting to this page thinking it was not resolved. Thank you. – shkschneider Aug 30 '12 at 07:38

1 Answers1

1

The reason you don't get a scrollbar is because your ViewPager (and RelativeLayout) has it's height set to match_parent instead of wrap_content. This causes it to match the dimensions of your ScrollView, which kind of defeats the purpose of the ScrollView in the first place.. The contents of your ScrollView should be higher/taller than your ScrollView itself.

To conclude, you should set both your RelativeLayout's height and your ViewPager's height to wrap_content. Also, you didn't set the order/position in which you want RelativeLayout's children to appear; you might want to change that (or use LinearLayout instead). Example:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fadeScrollbars="true"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/menu" />

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

</ScrollView>
Reinier
  • 3,836
  • 1
  • 27
  • 28
  • I copied your xml but it doesnt scroll either. I think theres a fundamental problem with ViewPager in scrollView? – user1324936 Aug 29 '12 at 20:35
  • Yeah, like the answer in the link you provided above says, you can fix this by extending `ScrollView` and overriding it's `onInterceptTouchEvent(...)`-method. You should provide an answer to your own post and accept it. – Reinier Aug 30 '12 at 07:41