view pager not smooth when embedded within scrollview?

依然范特西╮ 提交于 2019-12-23 17:23:47

问题


I have requirement like play store app where there is view pager with images and videos and scroll to view details .Unfortunately when user scrolls the scroll is jumpy but if i remove the scrollview the view pager works perfectly fine .

The layout look and feel is something like this http://cl.ly/MBRB

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

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



    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="160dp"
        android:background="@drawable/loading_image"
        android:gravity="top"
        android:orientation="vertical" >

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

        <com.viewpagerindicator.CirclePageIndicator
            android:id="@+id/titles"
            style="@style/CirclePageIndicator"
            android:layout_alignParentBottom="true"
            android:padding="10dip"
            android:paddingBottom="10dp" />
    </RelativeLayout>

    <include layout="@layout/app_screen_menu" />
</LinearLayout>
</ScrollView>

Btw i am loading images from server .

Thanks


回答1:


You are using 2 scrollisteners

  • A viewpager uses a scrolllistener
  • A scrollview uses a scrolllistener

These two scrollistener are fighting for the ScrollEvent. You can solve this by implementing onInterceptTouch. In this method you can decide who wins the fight over the ScrollEvent

Take a look at this protected post regarding a similair issue containing 2 scrollviews



来源:https://stackoverflow.com/questions/14326317/view-pager-not-smooth-when-embedded-within-scrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!