I am using slide animation when transaction replacing fragments
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager
.beginTransaction();
transaction.setCustomAnimations(
R.anim.anim_from_left, R.anim.anim_to_right);
transaction.replace(R.id.frame_drugstore, fragment).commit();
Animation for fragment which comes from left:
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="translationX"
android:valueType="floatType"
android:valueFrom="-720"
android:valueTo="0" />
</set>
Animation for fragment which to the right:
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="translationX"
android:valueType="floatType"
android:valueFrom="0"
android:valueTo="720" />
</set>
On my Galaxy Nexus (1280×720) this is working as needed. I am thinking about devices which have no 720px width screen.
How to set objectAnimator's valueFrom and valueTo according to screen size?