Android片段翻译从右到左

时间:2014-04-01 09:32:09

标签: android android-fragments translation slide

我希望在左边有一个翻译,当一个片段消失以显示另一个片段时。

我的翻译是:

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>

但它没有运行,只有从左到右的翻译运行...为什么?

2 个答案:

答案 0 :(得分:9)

slide1.xml

<?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%" />

slide2.xml

<?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%" />

Java代码

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);

enter image description here