android手势检测器中如何用onfling方法替换图像



我试图在onFling方法中替换图像在android的手势检测器中滑动。它没有改变,有人能告诉如何在android的手势检测器中替换onFling方法中的图像下面是我的代码

 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                try {
                    if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)

                        return false;
                    // right to left swipe
                    if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                        View view; 
                        View child;
                        LayoutInflater inflater = (LayoutInflater)   context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
                        view = inflater.inflate(R.layout.generic_help, null);
                        ImageView helpImage=(ImageView)view.findViewById(R.id.helpImage);
                        helpImage.setImageResource(R.drawable.an_nav_screen);


                        Toast.makeText(context, "Left Swipe", Toast.LENGTH_SHORT).show();

                        System.out.println("left swipe");
                    }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                        System.out.println("right swipe");
                        Toast.makeText(context, "Right Swipe", Toast.LENGTH_SHORT).show();
                    }
                } catch (Exception e) {
                    // nothing
                }
                return true;

谢谢

try this,

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            return fasle;
        } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            LayoutInflater inflater = (LayoutInflater)   context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
            view = inflater.inflate(R.layout.generic_help, null);
            ImageView helpImage=(ImageView)view.findViewById(R.id.helpImage);
            helpImage.setImageResource(R.drawable.an_nav_screen);
            return true;
        }
        if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
            return false;
        } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
            return false;
        }
        return false;
    }

这可能对你有帮助

最新更新