简体   繁体   English

如何在Android中使用View Pager滚动布局?

[英]how to scroll layout with view pager in android?

I just try to do scroll my activity in which tab + view pager but im not getting success. 我只是尝试滚动我的活动,在其中使用选项卡+查看寻呼机,但是即时通讯没有成功。 Below i show what happened when i'm using scroll. 下面我展示了当我使用滚动条时发生了什么。

shown view pager image and xml code 显示的视图寻呼机图像和xml代码

在此处输入图片说明

not scroll vertically now 现在不垂直滚动

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="250dp" >

            <ImageView
                android:id="@+id/profile_user_banner_profile_user"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@string/shown_image"
                android:scaleType="fitXY"
                android:src="@drawable/banner" />

        </RelativeLayout>

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

            <biz.xicom.defindme.profileuser.TabPageIndicator
                android:id="@+id/indicator"
                android:layout_width="fill_parent"
                android:layout_height="40dp"
                android:background="@drawable/tabs_bg"
                android:fillViewport="true" />

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#f1eee7"
                android:scrollbars="vertical" />

        </LinearLayout>

not shown viewpager bcz im add view pager on scrollview but i dnt now why ding this 未显示viewpager bcz im在scrollview上添加视图分页器,但我现在不知道为什么

在此处输入图片说明

now not shown anything which is on view pager when add view pager on scroll view 现在在滚动视图上添加视图分页器时未显示视图分页器上的任何内容

 <ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="250dp" >

            <ImageView
                android:id="@+id/profile_user_banner_profile_user"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@string/shown_image"
                android:scaleType="fitXY"
                android:src="@drawable/banner" />

        </RelativeLayout>

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

            <biz.xicom.defindme.profileuser.TabPageIndicator
                android:id="@+id/indicator"
                android:layout_width="fill_parent"
                android:layout_height="40dp"
                android:background="@drawable/tabs_bg"
                android:fillViewport="true" />

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#f1eee7"
                android:scrollbars="vertical" />

        </LinearLayout>
    </LinearLayout>
</ScrollView>

scrolling but viewpager height fixed now you see what happend 滚动但viewpager的高度已固定,现在您可以看到发生了什么

shown view pager 显示的视图寻呼机

在此处输入图片说明

now u see below image with scrolling and have u see scroll which i point 现在你看到下面的图像与滚动,并且你看到我指向的滚动

在此处输入图片说明

  <ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="250dp" >

            <ImageView
                android:id="@+id/profile_user_banner_profile_user"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@string/shown_image"
                android:scaleType="fitXY"
                android:src="@drawable/banner" />

        </RelativeLayout>

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

            <biz.xicom.defindme.profileuser.TabPageIndicator
                android:id="@+id/indicator"
                android:layout_width="fill_parent"
                android:layout_height="40dp"
                android:background="@drawable/tabs_bg"
                android:fillViewport="true" />

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="100000dp"
                android:background="#f1eee7"
                android:scrollbars="vertical" />
        </LinearLayout>
    </LinearLayout>
</ScrollView>

i want above thing to do but without fixed (android.support.v4.view.ViewPager android:layout_height="100000dp") . 我想做以上事情,但没有固定(android.support.v4.view.ViewPager android:layout_height="100000dp") So how can i achieve this task. 那么我怎样才能完成这项任务。

您在该布局中添加ScrollView,在其中添加/填充布局内容。如果使用Fragment,则将ScrollView保留在FragmentLayout中,而不是ViewPager布局中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM