public void redirectToAttachedFragment(int to, int type) {
FragmentManager fragmentManager=getFragmentManager();
FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
BaseFragment subFragment=attachedFragmentArray.get(to);
if (type == 1) {
fragmentTransaction.setCustomAnimations(
R.animator.fragment_slide_left_enter,
R.animator.fragment_slide_right_exit
);
//系统动画
// fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
} else if (type == -1) {
fragmentTransaction.setCustomAnimations(
R.animator.fragment_slide_right_enter,
R.animator.fragment_slide_left_exit
);
}
fragmentTransaction.replace(R.id.flFilterSortContainer, subFragment);
fragmentTransaction.commitAllowingStateLoss();
}
动画代码:
<?xml version="1.0" encoding="utf-8"?>
android:interpolator="@android:anim/decelerate_interpolator"
android:valueFrom="380dp"
android:valueTo="0dp"
android:valueType="floatType"
android:propertyName="translationX"
android:duration="200" />
动画代码:
<?xml version="1.0" encoding="utf-8"?>
android:interpolator="@android:anim/decelerate_interpolator"
android:valueFrom="0dp"
android:valueTo="-380dp"
android:valueType="floatType"
android:propertyName="translationX"
android:duration="200" />
问题来了:切换时中间有一条缝隙
实际场景中就会看到一个白块飞速闪过。是什么原因?有解吗?