xukai59740
whateverXk
采纳率28.6%
2016-07-01 08:47 阅读 1.5k

Android Fragment 切换动画中间有间隙

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" />

问题来了:切换时中间有一条缝隙图片说明

实际场景中就会看到一个白块飞速闪过。是什么原因?有解吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

相关推荐