我需要像这样在Activities或Fragments之间制作动画。我使用Android Api >=14.
http://www.youtube.com/watch?v=cNMqIv5Ocnk - 这是Nexus5 Launcher
我已经尝试过使用Android ObjectAnimator的动画,但它与这个视频动画并不是很相似。
提前致谢。
我试过这段代码
(适用gla_on.xml):
<objectAnimator
android:duration="0"
android:propertyName="alpha"
android:valueFrom="1.0"
android:valueTo="0.0" />
<objectAnimator
android:duration="1000"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="scaleY"
android:valueFrom="1"
android:valueTo="12" />
<objectAnimator
android:duration="1000"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="scaleX"
android:valueFrom="1"
android:valueTo="12" />
的 gla_off.xml:
<objectAnimator
android:duration="0"
android:propertyName="alpha"
android:valueFrom="0.0"
android:valueTo="1.0" />
<objectAnimator
android:duration="1000"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="scaleY"
android:valueFrom="1"
android:valueTo="12" />
<objectAnimator
android:duration="1000"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="scaleX"
android:valueFrom="1"
android:valueTo="12" />
并将其放入此代码片段中:
getFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.gla_on, R.anim.gla_off)
.replace(R.id.container, new NextFragment())
.addToBackStack(null)
.commit();
但是NextFragment没有显示
答案 0 :(得分:6)
<强> CLOSED 强>
经过多次尝试,我找到了决定。
(您可以在此处观看结果 - http://www.youtube.com/watch?v=Npn0c68OkYs)
我在Android资源文件夹 anim
中创建了4个动画<强> gla_there_come.xml 强>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<objectAnimator
android:duration="500"
android:propertyName="alpha"
android:valueFrom="0.0"
android:valueTo="1.0" />
<objectAnimator
android:duration="500"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="scaleY"
android:valueFrom="0"
android:valueTo="1" />
<objectAnimator
android:duration="500"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="scaleX"
android:valueFrom="0"
android:valueTo="1" />
</set>
<强> gla_there_gone.xml 强>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<objectAnimator
android:duration="500"
android:propertyName="alpha"
android:valueFrom="1.0"
android:valueTo="0.0" />
<objectAnimator
android:duration="500"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="scaleY"
android:valueFrom="1"
android:valueTo="12" />
<objectAnimator
android:duration="500"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="scaleX"
android:valueFrom="1"
android:valueTo="12" />
</set>
<强> gla_back_gone.xml 强>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<objectAnimator
android:duration="500"
android:propertyName="alpha"
android:valueFrom="0.0"
android:valueTo="1.0" />
<objectAnimator
android:duration="500"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="scaleY"
android:valueFrom="12"
android:valueTo="1" />
<objectAnimator
android:duration="500"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="scaleX"
android:valueFrom="12"
android:valueTo="1" />
</set>
<强> gla_back_come.xml 强>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<objectAnimator
android:duration="500"
android:propertyName="alpha"
android:valueFrom="1.0"
android:valueTo="0.0" />
<objectAnimator
android:duration="500"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="scaleY"
android:valueFrom="1"
android:valueTo="0" />
<objectAnimator
android:duration="500"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="scaleX"
android:valueFrom="1"
android:valueTo="0" />
</set>
我将下面的代码添加到我的FragmentActivity中:
public void goToNext() {
mShowingNext = true;
getFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.gla_there_come, R.anim.gla_there_gone)
.replace(R.id.container, new NextFragment())
.commit();
}
public void goBack() {
mShowingNext = false;
getFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.gla_back_gone, R.anim.gla_back_come)
.replace(R.id.container, new MainFragment())
.commit();
}