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

2
  • stackoverflow.com/questions/2646028/… found the solution Commented Aug 29, 2012 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. Commented Aug 30, 2012 at 7:38

1 Answer 1

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> 
Sign up to request clarification or add additional context in comments.

2 Comments

I copied your xml but it doesnt scroll either. I think theres a fundamental problem with ViewPager in scrollView?
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.