向左和向后滑动 - 片段

时间:2015-02-03 15:08:45

标签: java android android-activity android-fragments

我正在尝试将片段从let向右滑动以获得滑动菜单效果。但片段从底部向上滑动。 ylocation是我活动中心顶部的一个按钮。

            newAddressFragment = new AddressFagment(AddressActivity.this,
                    ylocation);
            AddressActivity.this
                    .getFragmentManager()
                    .beginTransaction()
                    .setCustomAnimations(R.anim.enter_from_left, R.anim.exit_from_bottom)
                    .addToBackStack(newAddressFragment.toString())
                    .replace(R.id.address_frame, newAddressFragment,
                            newAddressFragment.toString())
                    .commit();

enter_from_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate android:duration="5000" android:fromXDelta="-100%" android:toXDelta="0%"/>
<alpha android:duration="5000" android:fromAlpha="0.0" android:toAlpha="1.0" />   
</set>

exit_to_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate android:duration="5000" android:fromXDelta="0%" android:toXDelta="-100%"/>
<alpha android:duration="5000" android:fromAlpha="1.0" android:toAlpha="0.0" />
</set>

1 个答案:

答案 0 :(得分:0)

经过一些解决方法后,有效的代码是:

getSupportFragmentManager()
                        .beginTransaction()
                        .setCustomAnimations(R.anim.enter_from_left, 0, 0,
                                R.anim.exit_to_left)
                        .add(R.id.dummy, new SliderMenuActivity())
                        .addToBackStack("animation").commit();

enter_from_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:duration="@android:integer/config_mediumAnimTime">
<translate
        android:fromXDelta="-100%p"
        android:startOffset="25"
        android:toXDelta="0" />
</set> 

exit_to_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:duration="@android:integer/config_mediumAnimTime">
<translate
        android:fromXDelta="0"
        android:startOffset="25"
        android:toXDelta="-100%p"/>

</set>

希望这会有所帮助!!