带有一些音符的 alpha 动画向上/向下滑动
slide_up.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@integer/activity_transition_time"
>
<translate
android:fromYDelta="100%p"
android:toYDelta="0"/>
<alpha
android:fromAlpha="0.5"
android:toAlpha="1"/>
</set>
slide_down.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@integer/activity_transition_time"
>
<translate
android:fromYDelta="0"
android:toYDelta="100%p"/>
<alpha
android:fromAlpha="1"
android:toAlpha="0.5"/>
</set>
no_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@integer/activity_transition_time"
android:fromYDelta="0"
android:toYDelta="0"/>
第一个活动
startActivity(new Intent(this, SecondActivity.class));
overridePendingTransition(R.anim.slide_up, R.anim.no_animation); // remember to put it after startActivity, if you put it to above, animation will not working
// document say if we don't want animation we can put 0. However, if we put 0 instead of R.anim.no_animation, the exist activity will become black when animate
第二次活动
finish();
overridePendingTransition(R.anim.no_animation, R.anim.slide_down);
完成
更多
当呈现视图模型(如https://www.youtube.com/watch?v=deZobvh2064)时,我尝试制作像 iOS 动画一样的幻灯片动画,但失败了。
查看iOS当前动画你会看到:从底部开始的动画带有alpha(大约50%)然后它变得非常快然后变慢,动画时间大约> 500ms(我使用修剪视频工具来计算动画时间
https://www.kapwing.com/trim-video 所以它不能完全 100%)
然后我尝试申请android。
为了制作 alpha,我使用 <alpha> 并成功。
为了让动画启动得快于慢,我使用了android:interpolator="a decelerate interpolator",但它几乎失败了。
Android 中有 3 个默认 decelerate interpolator
@android:interpolator/decelerate_quad -> 因子 = 1
@android:interpolator/decelerate_cubic -> 因子 = 1.5
@android:interpolator/decelerate_quint _> 因子 = 2.5
(更高的因素 动画从一开始就开始更快,在结束时更慢)
这是一个很好的教程http://cogitolearning.co.uk/2013/10/android-animations-tutorial-5-more-on-interpolators/ 了解它
我试过上面的3个我不能像iOS那样实现,动画不能像iOS那样启动更快。然后我创建了一个自定义 decelerateInterpolator 和 factor = 3 like
<?xml version="1.0" encoding="utf-8"?>
<decelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:factor="3" />
我从500 -> 750 增加持续时间。它运行良好(与 iOS 非常相似)。但是,它只在某些设备上运行良好,在某些设备上动画很慢。后来,我知道不同设备上的动画可能会有所不同(例如:某些设备会更快,而某些设备会更慢)所以我不能让它在所有 Android 设备上都相似。因此我不使用interpolator。我不知道我的测试是否准确 100%,但我希望这次经历对您有所帮助