2013年9月18日星期三

[Android] ScrollView embedded ViewPager, ViewPager sliding problems

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 proposed to achieve
------ eference ---- GroupView -----------------------------------
already own implementation , the need to rewrite ScrollView, the following is 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
------ eference ------------------------- --------------
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 ?
------ eference --------------------------------------- < br> Great God really to force , quite so!
------ eference --------------------------------------- < br> top Great God
------ eference - --------------------------------------
top Great God ! ! !
------ eference --------------------------------------- < br> If yes tgyhrfuj741 said, although can be achieved, but sliding around scrollview not useful , I am now the main problem is that there is a lateral view of the sliding scrollview subview has a slide up and down scrollview, embedded in a child view viewpager, but viewpager sliding around events and outermost sliding around scrollview event of a conflict , ask how to solve
------ eference ---------- -----------------------------
in scrollview put a viewpager, then viewpager put inside listview, showing no data is how ah , seeking god exhibitions.
------ eference --------------------------------------- < br> Where to call this method , find great God enlighten
------ eference --------------------------- ------------
+ + + + + + + + pretty good. . .

没有评论:

发表评论