I have a problem about the topic and now my situation is i have a viewpager inside scrollview and these inside emilsjolander FlipView, the structure look like:
<FlipView>
<ScrollView>
<ViewPager>
</ViewPager>
</ScrollView>
</FlipView>
And Because some issue of viewpager cannot detect touch so i just implement the custom Viewpager.
after i implemented the custom Viewpager, the touch issue is fixed but the viewpager has a problem about the animation.
when i swipe the viewpager, sometimes it work perfect but sometimes the viewpager just change the item without animation and it seem the first item change to Sec Item must cause this case. So i just put some log into startScroll method of ScrollerCustomDuration class and i found that when the viewpager change without animation, the startScroll method of ScrollerCustomDuration is not call.
So sorry for my poor english and thank you for all help, please let me know if u need me to provide more detail for this problem.
CustomViewPager Class:
public class CustomViewPager extends ViewPager {
private ScrollerCustomDuration mScroller = null;
public CustomViewPager(Context context) {
super(context);
postInitViewPager();
}
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
postInitViewPager();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
Log.e("onInterceptTouchEvent",event.toString());
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
this.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return super.onInterceptTouchEvent(event);
}
private void postInitViewPager() {
try {
Class<?> viewpager = ViewPager.class;
Field scroller = viewpager.getDeclaredField("mScroller");
scroller.setAccessible(true);
Field interpolator = viewpager.getDeclaredField("sInterpolator");
interpolator.setAccessible(true);
mScroller = new ScrollerCustomDuration(getContext(),
(Interpolator) interpolator.get(null));
scroller.set(this, mScroller);
} catch (Exception e) {
Log.e("MyPager", e.getMessage());
}
}
public void setScrollDurationFactor(double scrollFactor) {
mScroller.setScrollDurationFactor(scrollFactor);
}}
ScrollerCustomDuration Class :
public class ScrollerCustomDuration extends Scroller {
private double mScrollFactor = 1;
public ScrollerCustomDuration(Context context) {
super(context);
}
public ScrollerCustomDuration(Context context, Interpolator interpolator) {
super(context, interpolator);
}
@SuppressLint("NewApi")
public ScrollerCustomDuration(Context context, Interpolator interpolator, boolean flywheel) {
super(context, interpolator, flywheel);
}
/**
* Set the factor by which the duration will change
*/
public void setScrollDurationFactor(double scrollFactor) {
mScrollFactor = scrollFactor;
}
@Override
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
Log.e("##### FIX flash issue",""+startX);
Log.e("##### FIX flash issue",""+startY);
Log.e("##### FIX flash issue",""+dx);
Log.e("##### FIX flash issue",""+dy);
Log.e("##### FIX flash issue",""+duration);
super.startScroll(startX, startY, dx, dy, (int) (duration * mScrollFactor));
}
}
i just fixed the problem. it seem the problem is not about ontouch. i just refresh the flipview when flipview flip
the below code fixed my problem
fv.setOnFlipListener(new FlipView.OnFlipListener() {
@Override
public void onFlippedToPage(FlipView v, int position, long id) {
((BaseAdapter)fv.getAdapter()).notifyDataSetChanged();
}
});