让 ImageView 在滑动手势中呈现动画效果

发布于 2024-12-22 05:25:07 字数 1060 浏览 2 评论 0原文

当用户从左到右触摸屏幕时,我可以做出一个检测运动的手势。
但我不知道如何让图像随着该运动而移动。
这样做的目的是在我的应用程序中实现锁定屏幕,就像 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浸婚纱 2024-12-29 05:25:07

请参阅下面的链接,它可能对您有帮助。本例中提供了滑动(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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文