android对象动画转换和alpahn
我正在尝试动画片段过渡,我成功地动画过渡,但我也需要在同一时间,使淡出或在阿尔法。 这是我的代码:android对象动画转换和alpahn,android,animation,Android,Animation,我正在尝试动画片段过渡,我成功地动画过渡,但我也需要在同一时间,使淡出或在阿尔法。 这是我的代码: private void loadFragment(Fragment frag, String tag) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(
private void loadFragment(Fragment frag, String tag) {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction =
fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(R.animator.enter_from_left,
R.animator.exit_from_right, R.animator.enter_from_right,
R.animator.exit_from_left);
fragmentTransaction.replace(R.id.frameLayout, frag, tag);
fragmentTransaction.addToBackStack(tag);
fragmentTransaction.commit();
}
以下是动画师:
这是从左开始的输入:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="450"
android:propertyName="x"
android:valueFrom="1000"
android:valueTo="0"
android:valueType="floatType"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="450"
android:propertyName="x"
android:valueFrom="0"
android:valueTo="1000"
android:valueType="floatType"/>
</set>
这是从右边进入的地方
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="450"
android:propertyName="x"
android:valueFrom="1000"
android:valueTo="0"
android:valueType="floatType"/>
</set>
这是左边的出口:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="450"
android:propertyName="x"
android:valueFrom="1000"
android:valueTo="0"
android:valueType="floatType"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="450"
android:propertyName="x"
android:valueFrom="0"
android:valueTo="1000"
android:valueType="floatType"/>
</set>
这是右边的出口:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="450"
android:propertyName="x"
android:valueFrom="0"
android:valueTo="-1000"
android:valueType="floatType"/>
</set>
您可以在xml中定义的标记内指定多个animator对象,还可以指定它们一起播放或按顺序播放的顺序 下面是如何更改xml以实现所需
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:ordering="together">
<objectAnimator
android:duration="450"
android:propertyName="x"
android:valueFrom="1000"
android:valueTo="0"
android:valueType="floatType"/>
<objectAnimator
android:duration="450"
android:valueFrom="0f"
android:propertyName="alpha"
android:valueTo="1f" />
太好了。。。请接受答案,以便其他人受益。