如何在android中移动图像
我目前正在开发galaxy s4应用程序,在该应用程序中,我希望使用移动的手指拍摄运动图像,但如何实现此onHoverListener。请帮忙。如何在android中移动图像,android,Android,我目前正在开发galaxy s4应用程序,在该应用程序中,我希望使用移动的手指拍摄运动图像,但如何实现此onHoverListener。请帮忙。 提前感谢。在您的图像上实现touch listener,在您的活动中也实现touchevent,而不是hoverListener。然后你可以使用OnTouchEvent的actionMove 当用户执行actionMove时,请使用motionEvent对象查找坐标,并使用translate动画将视图转换为这些坐标。这将使您看起来好像正在移动图像。您可
提前感谢。在您的图像上实现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坐标。移动将导致图像闪烁……一次显示两个图像,即图像不能随手指平滑移动。