2013年8月14日星期三

Android ScrollView embedded ViewPager, ViewPager sliding problem

When you switch on the sliding ViewPager must remain completely horizontal sliding . Should the sliding direction of the sliding occurs when tilted ScrollView the scroll event is triggered , and the sliding ViewPager will terminate and change back to the original look .

How can I make when sliding in ViewPager ScrollView not scroll .

ScrollView tried rewriting the onTouchEvent, but to no avail.
------ Solution ---------------------------------------- ----
the problem I have encountered , could not find a good way , and finally I put ScrollView deleted , if we want to keep it suggested GroupView achieve
------ For reference only - -------------------------------------
already own implementation , the need to rewrite ScrollView, Here is the code


package com.zp365.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ScrollView;

/**
* 解决ScrollView嵌套ViewPager出现的滑动冲突问题
*/
public class ScrollView1 extends ScrollView {
private boolean canScroll;

private GestureDetector mGestureDetector;
View.OnTouchListener mGestureListener;

public ScrollView1(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(new YScrollDetector());
canScroll = true;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if(ev.getAction() == MotionEvent.ACTION_UP)
canScroll = true;
return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
}

class YScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if(canScroll)
if (Math.abs(distanceY) >= Math.abs(distanceX))
canScroll = true;
else
canScroll = false;
return canScroll;
}
}
}


ScrollView with this custom ScrollView on the line instead of the original
------ For reference only ----------------------- ----------------
Great God I ask how to call a custom scroll it ? Not directly defined in the xml before , and now need how to call it ?
------ For reference only -------------------------------------- -
Great God really to force , quite so!
------ For reference only -------------------------------------- -
top Great God

没有评论:

发表评论