如何在android中的手势检测器中取代onfling方法中的图像

时间:2014-05-21 10:00:39

标签: android android-gesture

我正在尝试替换onFling Mehtod中的图像以在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;

由于

1 个答案:

答案 0 :(得分:0)

试试这个,

@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;
    }

这可能会对你有所帮助