我想停止动画,一旦我在button..I点击意味着我要暂停被点击时有动画显示一个按钮,并希望在地方button.I的显示图像要为API级> 11做到这一点。我使用的价值为动画帮助animation.Please
Answer 1:
还有在API级别11.暂停/恢复动画API等级19已添加的功能没有支持的API。
然而,这里是一个你可以尝试的解决方案https://stackoverflow.com/a/7840895/3025732
Answer 2:
我所做的就是创建自己的interpolatedTime
价值,而忽略了一个发送。
如果动画暂停时,我不断更新我经过的时间。 然后,我caluclate我自己插的时间价值和使用,不管是什么动画我做的。
/**
* The animator for the LinearProgressBar.
*/
class LinearProgressBarAnimator extends Animation
{
private LinearProgressBar _bar;
/**
* The desired fill percent when done animating.
*/
private float _newFillPercent;
/**
* The current fill percent.
*/
private float _oldFillPercent;
/**
* Keeps track of if this object is in a paused state.
*/
private boolean _paused;
/**
* TimeConstants trackers to fire _onSecondTick
* at consistent 1 second intervals.
*/
private long _accumulatedTickTime;
private long _lastAccumulatedTime;
/**
* Creates a linear progress bar animator with the reference bar and desired fill percent.
* Call Animate() in order to make it animate the ProgressBar.
* @param bar
* @param newFillPercent
*/
public LinearProgressBarAnimator(LinearProgressBar bar, float newFillPercent)
{
super();
_newFillPercent = newFillPercent;
_oldFillPercent = bar.getFillPercent();
_bar = bar;
_paused = false;
_accumulatedTickTime = 0;
_lastAccumulatedTime = TimeConstants.NOT_SET;
}
/**
* Applies the interpolated change in fill percent.
* @param interpolatedTime
* @param transformation
*/
@Override
protected void applyTransformation(float interpolatedTime, Transformation transformation)
{
if (_lastAccumulatedTime == TimeConstants.NOT_SET || _paused)
{
_lastAccumulatedTime = System.currentTimeMillis();
return;
}
_accumulatedTickTime += System.currentTimeMillis() - _lastAccumulatedTime;
// This handles pausing, the passed interpolatedTime is ignored
float adjustedInterpolatedTimed = (float)_accumulatedTickTime / (float)getDuration();
float newTimeAdjustedFillPercent = _oldFillPercent + ((_newFillPercent - _oldFillPercent) * adjustedInterpolatedTimed);
_bar.setFillPercent(newTimeAdjustedFillPercent);
_bar.requestLayout();
_lastAccumulatedTime = System.currentTimeMillis();
}
public void pause()
{
_paused = true;
}
public void play()
{
_paused = false;
}
}
文章来源: Android Pause animation