I want to reach a specific fragment transition behaviour ,as I mention in the question, I want my fragment to appears from the right and disappears in the same direction back to the point it starts from.. These are my xml animations :
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%" />
and here are the different ways that I've tried to achieve the fragment animation :
When the fragment appears :
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));
}
});
When the fragment disappears method 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);
}
});
When the fragment disappears method 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);
}
});
unfortunately none of those worked as I expect, May this image can explain more what I want : image Thank you in advance.