android - 通过重启活动继续动画(Android)
问题描述
我有这个代码:
Refresh.startAnimation(
AnimationUtils.loadAnimation(getActivity(),R.anim.rotate));
Intent intent = getActivity().getIntent();
getActivity().finish();
getActivity().overridePendingTransition(0, 0);
startActivity(intent);
我想要它,所以在活动重置后,“刷新”静止图像上的动画会继续。我该怎么做呢?现在它只是在重置时停止。
解决方案
//code to restart you activity
public static void restartActivity(Activity activity){
Intent intent = new Intent();
intent.setClass(activity, activity.getClass());
activity.startActivity(intent);
activity.overridePendingTransition(R.anim.slideup, R.anim.keep_activity_static);
activity.finish();
}
//now this is to animate the exit of activity
@Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.keep_activity_static, R.anim.slidedown);
}
//now the anim file keep_activity_static
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%p"
android:toYDelta="0%p"
android:fillAfter="true"
android:duration="1000" />
</set>
//anim file slidedown
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%p"
android:toYDelta="100%p"
android:fillAfter="true"
android:duration="200"/>
</set>
//anim file slideup
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="100%p"
android:toYDelta="0%p"
android:fillAfter="true"
android:duration="200"/>
</set>
推荐阅读
- java - Java 内存模型顺序一致性与 Leslie Lamport 定义不同吗?
- javascript - 如何在输入框中显示数量的总数
- java - Java 处理 - 使用 text() 但窗口上没有显示任何内容
- assembly - 很少的汇编语法问题和反汇编代码的解释
- php - 如何在 Android TextView 中显示 PHP 内容?
- opencv - 细化边缘和轮廓检测
- qb64 - 检测 QB64 中的 SHARE
- php - Google App Engine 不自动缩放 php
- php - 重复结果无限滚动API PHP
- svn - 在本地修改文件后但在提交之前的 SVN 更新