Mix*_*Mix 227 animation android
我需要停止正在运行的翻译动画.该.cancel()方法Animation无效; 无论如何,动画一直持续到最后.
你如何取消正在运行的动画?
Com*_*are 483
打电话clearAnimation()给View你打电话startAnimation().
Sea*_*eau 36
在Android 4.4.4上,似乎唯一可以阻止View上的alpha淡入淡出动画的方式是调用View.animate().cancel()(即调用.cancel()View ViewPropertyAnimator).
这是我在ICS之前和之后用于兼容性的代码:
public void stopAnimation(View v) {
v.clearAnimation();
if (canCancelAnimation()) {
v.animate().cancel();
}
}
Run Code Online (Sandbox Code Playgroud)
...用方法:
/**
* Returns true if the API level supports canceling existing animations via the
* ViewPropertyAnimator, and false if it does not
* @return true if the API level supports canceling existing animations via the
* ViewPropertyAnimator, and false if it does not
*/
public static boolean canCancelAnimation() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
}
Run Code Online (Sandbox Code Playgroud)
这是我要停止的动画:
v.setAlpha(0f);
v.setVisibility(View.VISIBLE);
// Animate the content view to 100% opacity, and clear any animation listener set on the view.
v.animate()
.alpha(1f)
.setDuration(animationDuration)
.setListener(null);
Run Code Online (Sandbox Code Playgroud)
DjP*_*DjP 18
如果您正在使用动画侦听器,请设置v.setAnimationListener(null).对所有选项使用以下代码.
v.getAnimation().cancel();
v.clearAnimation();
animation.setAnimationListener(null);
Run Code Online (Sandbox Code Playgroud)
你必须使用 .clearAnimation(); UI线程中的方法:
runOnUiThread(new Runnable() {
@Override
public void run() {
v.clearAnimation();
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
125952 次 |
| 最近记录: |