Je veux atteindre un comportement de transition de fragment spécifique, comme je le mentionne dans la question, je veux que mon fragment apparaisse de la droite et disparaît dans le même sens jusqu'au point il commence à partir .. ce sont mes animations xml:La transition de fragment apparaît de droite à gauche, disparaît de gauche à droite (retour au point de départ)
right_to_left.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="1000"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
left_to_right.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="-100%"
android:toYDelta="0%" />
et voici les différentes façons que j'ai essayé de réaliser l'animation fragment:
Lorsque le fragment apparaît:
productHolder.fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putSerializable(Utils.productDetailsKey, productPojo);
ProductDetailsFragment productDetailsFragment = new ProductDetailsFragment();
productDetailsFragment.setArguments(bundle);
FragmentManager fragmentManager = activity.getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.setCustomAnimations(R.anim.product_animation_enter, R.anim.product_animation_enter);
transaction.add(R.id.newContainer, productDetailsFragment);
transaction.commit();
MainActivity.transparent.setBackgroundColor(ContextCompat.getColor(context, R.color.blackTransparent));
}
});
Lorsque le fragment disparaît Méthode 1:
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.product_animation_exit, R.anim.product_animation_exit);
transaction.remove(ProductDetailsFragment.this);
transaction.commitAllowingStateLoss();
MainActivity.transparent.setBackgroundColor(0x00000000);
}
});
Lorsque le fragment disparaît Méthode 2:
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.product_animation_exit);
animation.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
try {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.remove(ProductDetailsFragment.this);
transaction.commitAllowingStateLoss();
MainActivity.transparent.setBackgroundColor(0x00000000);
} catch (Exception e) {
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
getView().startAnimation(animation);
}
});
malheureusement aucun de ceux travaillé comme je l'attends, mai cette image peut expliquer plus ce que je veux: image Merci à l'avance.