Android 未调用DragGestureDetector
有人能告诉我我的代码出了什么问题吗?我正在使用customadapter类,当我尝试刷卡时,我在cardstack中设置了这个适配器,因为没有调用DragGestureDetector,所以刷卡不起作用 我正在使用这个图书馆项目 这是我的密码Android 未调用DragGestureDetector,android,interface,swipe-gesture,Android,Interface,Swipe Gesture,有人能告诉我我的代码出了什么问题吗?我正在使用customadapter类,当我尝试刷卡时,我在cardstack中设置了这个适配器,因为没有调用DragGestureDetector,所以刷卡不起作用 我正在使用这个图书馆项目 这是我的密码 private void setupAnimation(){ final View cardView = viewCollection.get(viewCollection.size()-1); mCardAnimator = ne
private void setupAnimation(){
final View cardView = viewCollection.get(viewCollection.size()-1);
mCardAnimator = new CardAnimator(viewCollection);
mCardAnimator.initLayout();
final DragGestureDetector dd = new DragGestureDetector(mContext,new DragGestureDetector.DragListener(){
@Override
public boolean onDragStart(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
Log.e("CardAnimator", "Dragstsrt");
mCardAnimator.drag(e1, e2, distanceX, distanceY);
return true;
}
@Override
public boolean onDragContinue(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
float x1 = e1.getRawX();
float y1 = e1.getRawY();
float x2 = e2.getRawX();
float y2 = e2.getRawY();
Log.e("CardAnimator", "Dragcontjnhue");
//float distance = CardUtils.distance(x1,y1,x2,y2);
final int direction = CardUtils.direction(x1,y1,x2,y2);
mCardAnimator.drag(e1,e2,distanceX,distanceY);
mEventListener.swipeContinue(direction, Math.abs(x2-x1),Math.abs(y2-y1));
return true;
}
@Override
public boolean onDragEnd(MotionEvent e1, MotionEvent e2) {
//reverse(e1,e2);
float x1 = e1.getRawX();
float y1 = e1.getRawY();
float x2 = e2.getRawX();
float y2 = e2.getRawY();
float distance = CardUtils.distance(x1,y1,x2,y2);
final int direction = CardUtils.direction(x1,y1,x2,y2);
boolean discard = mEventListener.swipeEnd(direction, distance);
if(discard){
Log.e("CardAnimator", "Dragend");
mCardAnimator.discard(direction, new AnimatorListenerAdapter(){
@Override
public void onAnimationEnd(Animator arg0) {
mCardAnimator.initLayout();
mIndex++;
mEventListener.discarded(mIndex,direction);
//mIndex = mIndex%mAdapter.getCount();
loadLast();
viewCollection.get(0).setOnTouchListener(null);
viewCollection.get(viewCollection.size()-1)
.setOnTouchListener(mOnTouchListener);
}
});
}else{
mCardAnimator.reverse(e1,e2);
}
return true;
}
@Override
public boolean onTapUp() {
mEventListener.topCardTapped();
return true;
}
}
);
mOnTouchListener = new OnTouchListener() {
private static final String DEBUG_TAG = "MotionEvents";
@Override
public boolean onTouch(View arg0, MotionEvent event) {
dd.onTouchEvent(event);
return true;
}
};
cardView.setOnTouchListener(mOnTouchListener);
}
@尼米特:
您应该重写onDown()并将返回值设置为true。您忘记了该方法。请这样尝试,如果出现任何问题,请务必通知我
class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
Log.e(DEBUG_TAG,"Action Scroll");
if(mListener == null) return true;
if( mStarted == false){
mListener.onDragStart(e1,e2,distanceX,distanceY);
mStarted = true;
}
else{
mListener.onDragContinue(e1,e2,distanceX,distanceY);
}
mOriginalEvent = e1;
return true;
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return mListener.onTapUp();
}
@Override
public boolean onDown(MotionEvent evt){
mOriginalEvent = evt;
return true;
}
如何添加此库?。当我尝试时,我无法添加这个库。我创建了一个与库集成的示例项目。我成功了,为我工作得很好。但是,当我尝试添加包含HTML内容的web视图时,滑动功能不起作用。如果有一个没有HTML内容或数据的web视图,或者在web视图之外,我们可以获得刷卡功能。但是我需要一个全屏的网络视图。那么刷卡功能是如何使用的,请帮助。