Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中移动图像_Android - Fatal编程技术网

如何在android中移动图像

如何在android中移动图像,android,Android,我目前正在开发galaxy s4应用程序,在该应用程序中,我希望使用移动的手指拍摄运动图像,但如何实现此onHoverListener。请帮忙。 提前感谢。在您的图像上实现touch listener,在您的活动中也实现touchevent,而不是hoverListener。然后你可以使用OnTouchEvent的actionMove 当用户执行actionMove时,请使用motionEvent对象查找坐标,并使用translate动画将视图转换为这些坐标。这将使您看起来好像正在移动图像。您可

我目前正在开发galaxy s4应用程序,在该应用程序中,我希望使用移动的手指拍摄运动图像,但如何实现此onHoverListener。请帮忙。
提前感谢。

在您的图像上实现touch listener,在您的活动中也实现touchevent,而不是hoverListener。然后你可以使用OnTouchEvent的actionMove


当用户执行actionMove时,请使用motionEvent对象查找坐标,并使用translate动画将视图转换为这些坐标。这将使您看起来好像正在移动图像。

您可以对图像视图执行onTouchListener(),如下所示:

img = ((ImageView) findViewById(R.id.img_arrow));

img.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent motionEvent) {
                int rawX = (int) motionEvent.getX();
                int rawY = (int) motionEvent.getY();
                if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
                    TranslateAnimation anim = new TranslateAnimation(rawX, rawY, 0, 0);
                    anim.setDuration(500L);
                    img.startAnimation(anim);
                }
                return true;
            }
});

这里我们将平移动画应用于我们的imageViewimg

请使用拖放,在MotionEvent中提供相同的imageView坐标。移动将导致图像闪烁……一次显示两个图像,即图像不能随手指平滑移动。