添加渐变色刷卡手势手势、渐变色

2023-09-06 17:04:59 作者:如果、你还爱我

现在我可以处理滑动手势,细跟的贴code。但我想补充一个背景颜色过渡,用户挥笔从一个方向到另一个。非常类似于股票的联系人应用程序做它的方式。我知道我将不得不使用一个GestureOverlay但我无法弄清楚如何我目前的code链接。是否有可能,或有更简单的方法来做到这一点?

Right now I can handle swipe gestures fine with the posted code. But I want to add a background color for the transition as the user swipes from one direction to another. Very similar to the way the stock contacts app does it. I know I will have to use a GestureOverlay but I can't figure out how to link that with my current code. Is it possible, or is there an easier way to do this?

    // inside my onCreate method
    View view = getLayoutInflater().inflate(R.layout.gesture_overlay, null);
    GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
    gestureOverlayView.addView(view);


    mGestureDetector = new GestureDetector(new MyGestureDetector());
    mGestureListener = new View.OnTouchListener() {
        public boolean onTouch(View view, MotionEvent event) {
            mLongPress = false;
            return mGestureDetector.onTouchEvent(event);
        }
    };

    // mListView.setOnItemClickListener(this);
    mListView.setOnTouchListener(mGestureListener);
}


class MyGestureDetector extends SimpleOnGestureListener {
    private static final int SWIPE_MIN_DISTANCE       = 120;
    private static final int SWIPE_MAX_OFF_PATH       = 200;
    private static final int SWIPE_THRESHOLD_VELOCITY = 200;

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
        return false;
    }
    // right to left swipe
    if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
            && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        return true;
    } else
        if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            return true;
        }

    return false;
}

}

推荐答案

是否截图来自三星手机?我之前已经实现这种效果。这刷卡吧不是一个渐变色,但只是用三张图片组成。

Does the screenshot comes from Samsung phone? I have implemented this effect before. This swipe bar isn't a gradient color but just composed with three pictures .

您可以通过反编译APK与 apktool 文件中获取这些照片

You can get these pictures by decompile the APK file with apktool