【问题标题】:how to create swipe action for gridview images?如何为 gridview 图像创建滑动动作?
【发布时间】:2016-06-20 16:22:04
【问题描述】:

我想为 gridview 图像创建 fling(swipe) 动作。我使用此链接实现了网格视图图像 http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/ 在这里,当我单击网格视图图像时,它将进入全屏图像。现在显示完整图像后,然后用手指触摸从左到右和从右到左滑动图像。这里不使用视图翻转器,因为这里有更多图像。这里单击哪个图像显示并向右或向左滑动。 谢谢

【问题讨论】:

    标签: android image gridview swipe


    【解决方案1】:

    为此,您可以使用 GestureDetector 和 View.onTouchListener

    这是我之前使用的一些代码的摘录:

    private int SWIPE_MIN_DISTANCE = 160;
    private int SWIPE_MAX_OFF_PATH = 250;
    private int SWIPE_THRESHOLD_VELOCITY = 200;
    private class MyGestureDetector extends SimpleOnGestureListener {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                    float velocityY) {
            try {
                // Move vertical too much?
                if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                    return false;
    
                float x1 = e1.getX(),
                      x2 = e2.getX();
    
                // Right to left swipe
                if (x1 - x2 > SWIPE_MIN_DISTANCE
                        && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    next();
    
                // Left to right swipe
                } else if (x2 - x1 > SWIPE_MIN_DISTANCE
                        && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    previous();
                }
            } catch (Exception e) {
                // nothing
            }
            return false;
        }
    }
    

    【讨论】:

    • 感谢@ndsmyter。但我有三个 java 文件,如 FullImage、ImageAdapter 和 GridView。以及我使用的这段代码,我认为这里的动画文件需要从左到右移动?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-27
    • 2011-03-17
    • 2013-09-12
    • 1970-01-01
    相关资源
    最近更新 更多