我希望在左边有一个翻译,当一个片段消失以显示另一个片段时。
我的翻译是:
ft.setCustomAnimations(R.anim.lefttoright,R.anim.righttoleft);
我的翻译离开&对:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="700"
android:fromXDelta="-100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="700"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="100%"
android:toYDelta="0%" />
</set>
但它没有运行,只有从左到右的翻译运行...为什么?
答案 0 :(得分:9)
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="350"
android:fromXDelta="100%"
android:toXDelta="0%" />
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="350"
android:fromXDelta="0"
android:toXDelta="-100%" />
ft.setCustomAnimations(R.anim.slide1, R.anim.slide2);
答案 1 :(得分:1)
在anim
目录
<强> slide_left_in.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="@integer/default_transaction_animation_duration"
android:fromXDelta="-100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
<强> slide_left_out.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="@integer/default_transaction_animation_duration"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="-100%"
android:toYDelta="0%" />
</set>
<强> slide_right_in.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="@integer/default_transaction_animation_duration"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
<强> slide_right_out.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="@integer/default_transaction_animation_duration"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="100%"
android:toYDelta="0%" />
</set>
在values
目录
<强> integers.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="default_transaction_animation_duration">350</integer>
</resources>
在Java中
fragmentTransaction.setCustomAnimations(R.anim.slide_right_in, R.anim.slide_left_out,
R.anim.slide_left_in, R.anim.slide_right_out);