美文网首页
Android 给Fragment添加显示和隐藏动画

Android 给Fragment添加显示和隐藏动画

作者: QXH313 | 来源:发表于2018-08-24 20:04 被阅读0次

1、显示

FragmentManager manager = getSupportFragmentManager();

Fragment fragment = manager.findFragmentByTag(Fragment.TAG);

if (fragment != null) return;

FragmentTransaction transaction = manager.beginTransaction();

transaction.setCustomAnimations(R.anim.slide_right_in, 0);

Fragment fragment = new Fragment();

transaction.add(R.id.frameContainer, fragment,Fragment.TAG);

transaction.commitAllowingStateLoss();

2、隐藏

FragmentManager manager = getSupportFragmentManager();

Fragment fragment =manager.findFragmentByTag(Fragment.TAG);

if (fragment != null) {

          FragmentTransaction transaction = manager.beginTransaction();

            transaction.setCustomAnimations(0, R.anim.slide_right_out);

            transaction.remove(fragment);

            transaction.commitAllowingStateLoss();

}

相关文章

网友评论

      本文标题:Android 给Fragment添加显示和隐藏动画

      本文链接:https://www.haomeiwen.com/subject/exviiftx.html