Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
570 views
in Technique[技术] by (71.8m points)

android - ViewPager in ScrollView

I need to have a ViewPager inside a ScrollView but ViewPager just does not appear when it's in ScrollView, everything is ok when i don't use ScrollView.

I've seen a couple questions like this being asked here on stackoverflow or on other sites and all of them have been answered that you have to put android:fillViewport="true" to your scrollview to fix the problem, but this solution doesnt work for me, ViewPager still does not appear even if i have android:fillViewport="true" in my ScrollView.

I guess something got changed in the android api's or something and this solution doesn't work anymore, does anyone know how i could possibly make a ViewPager appear in a ScrollView?

UPDATE: A working ScrollView layout XML:

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">


    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

            <android.support.v4.view.ViewPager
                android:id="@+id/itemsViewPager2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >
            </android.support.v4.view.ViewPager>
    </LinearLayout>
 </ScrollView>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I ran into a similar problem in the past. A View-Pager must have a set height (it cannot wrap-content). Since a ViewPager loads separate pages, and not all at once, it won't know what 'wrap-content' actually means. Setting the layout_height to fill_parent or a set dp allows the ViewPager to statically set it's height and react more accordingly within other layouts.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...