当前,我正在使用以下内容在2种背景色之间进行转换:
background_Transition.xml
<?xml version="1.0" encoding="UTF-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<!-- TODO: HIGHER FPS, may require programmatic transitioning -->
<item android:drawable="@drawable/background_start" />
<item android:drawable="@drawable/background_end" />
</transition>
background_start.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorPrimary" />
</shape>
background_end.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/background_end" />
</shape>
MainActivity.java
...
// fade from start to end
backgroundTransition.startTransition(DURATION);
// fade from current state to other state (used to fade from end to start)
backgroundTransition.reverseTransition(DURATION);
...
此解决方案有3个问题。
TODO:
评论中您可能已经注意到,在此过渡期间FPS确实很低。reverseTransition
类的Transition
方法不能像startTransition
那样幂等地工作。它翻转过渡状态。我将无法完全过渡到过渡的N个状态。