ikew0ng / SwipeBackLayout

An Android library that help you to build app with swipe back gesture.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

回弹速度好慢,像是没有力气

listenzz opened this issue · comments

经过分析原因,确定是下面的原因:

@Override
public int getViewHorizontalDragRange(View child) {
     return mEdgeFlag & (EDGE_LEFT | EDGE_RIGHT)
}

查看 ViewDragHelper 源码可知

private int computeSettleDuration(View child, int dx, int dy, int xvel, int yvel) {
    // ...
    int xduration = computeAxisDuration(dx, xvel, mCallback.getViewHorizontalDragRange(child));
     int yduration = computeAxisDuration(dy, yvel, mCallback.getViewVerticalDragRange(child));

     return (int) (xduration * xweight + yduration * yweight);
}

回弹时间是通过 getViewHorizontalDragRange 来计算的,像上面那种写法,回弹时就慢吞吞了。

不知道作者是处于什么考虑采用以上那种写法,我把它改成以下写法,回弹速度就正常了,也没发现有其它问题。

@Override
public int getViewHorizontalDragRange(View child) {
       if ((mEdgeFlag & EDGE_LEFT) == EDGE_LEFT) {
            return child.getWidth();
       } else if ( (mEdgeFlag & EDGE_RIGHT) == EDGE_RIGHT) {
            return -child.getWidth();
       }
        return 0;
}

大佬不提个PR吗