让 ImageView 在滑动手势中呈现动画效果
当用户从左到右触摸屏幕时,我可以做出一个检测运动的手势。
但我不知道如何让图像随着该运动而移动。
这样做的目的是在我的应用程序中实现锁定屏幕,就像 iPhone 锁定/解锁功能一样。
我想我必须做一些类似 image_swipe.setAnimate... 之类的事情。
如果有人有任何想法,请告诉我。
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
@Override
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(e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(getApplicationContext(), "Right Swipe", Toast.LENGTH_SHORT).show();
//i would like to make ImageView "image_swipe" move along with gesture
}
} catch (Exception e) {
}
return true;
}
I can make a gesture which detects a movement when the user touches the screen from left to right.
But I don't know how to make the image move along with that movement.
The purpose of this is to do a lock screen inside my application like the iPhone lock/unlock feature.
I guess I have to do something like image_swipe.setAnimate... or something.
If anyone has any idea, please let me know.
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
@Override
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(e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(getApplicationContext(), "Right Swipe", Toast.LENGTH_SHORT).show();
//i would like to make ImageView "image_swipe" move along with gesture
}
} catch (Exception e) {
}
return true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅下面的链接,它可能对您有帮助。本例中提供了滑动(onFling)屏幕时的图像移动。
CoverFlow 小部件示例
See the below link, it may help you. The image movement when you swipe (onFling) the screen is available in this example.
CoverFlow Widget Example