获取Android中的fling持续时间

获取Android中的fling持续时间,android,Android,Scroller类中的getDuration方法获取滚动的持续时间 我们可以用这个方法来获得投掷的持续时间吗?还是有其他方法可以做到这一点 public final int getDuration () Returns how long the scroll event will take, in milliseconds. Returns The duration of the scroll in milliseconds. 我们可以用这个方法来获得投掷的持续时间吗?或者是 还有别的办法

Scroller类中的getDuration方法获取滚动的持续时间

我们可以用这个方法来获得投掷的持续时间吗?还是有其他方法可以做到这一点

public final int getDuration ()

Returns how long the scroll event will take, in milliseconds.

Returns
The duration of the scroll in milliseconds.
我们可以用这个方法来获得投掷的持续时间吗?或者是 还有别的办法吗

public final int getDuration ()

Returns how long the scroll event will take, in milliseconds.

Returns
The duration of the scroll in milliseconds.
由于持续时间将在放纵开始时计算,因此我们在放纵过程中使用该方法得到的持续时间无疑是放纵的持续时间

顺便说一句,这个持续时间取决于投掷的初始速度。这是滚动条的代码片段,您可以看到它是如何计算的:

    /**
     * Returns how long the scroll event will take, in milliseconds.
     * 
     * @return The duration of the scroll in milliseconds.
     */
    public final int getDuration() {
        return mDuration;
    }

   // Code in the fling() method which will be called based on a fling gesture
   mDuration = getSplineFlingDuration(velocity);

    // The essential method.
    private int getSplineFlingDuration(float velocity) {
        final double l = getSplineDeceleration(velocity);
        final double decelMinusOne = DECELERATION_RATE - 1.0;
        return (int) (1000.0 * Math.exp(l / decelMinusOne));
    }
    private double getSplineDeceleration(float velocity) {
        return Math.log(INFLEXION * Math.abs(velocity) / (mFlingFriction * mPhysicalCoeff));
    }
更新:


如何在一次狂欢开始时计算持续时间

“在掷骰开始时”是指当滚动条的用户检测到掷骰手势时。如果他想使用滚动条的掷骰功能,则应使用适当的参数调用以下方法:

  public void fling(int startX, int startY, int velocityX, int velocityY,
            int minX, int maxX, int minY, int maxY) 

持续时间在上限方法中计算。它首先用velocityX和velocityY计算总速度,然后将速度传递给GetSplineFingDuration()方法以获得一个fling持续时间。我会先粘贴该方法的代码,我想你不难理解。

uhh我不确定这一点,但如果我没记错的话,您只需将两个事件的开始时间相减,就可以得到持续时间。
getDuration()
可用于“滚动”和“投掷”移动显示在投掷开始时可以计算持续时间吗?如果您能详细说明,我们将不胜感激。