使片段过渡同时为视图添加动画效果



我正在用片段B替换片段A并对其进行动画处理。片段 B 有一个带有TextViewListViewRelativeLayout。我可以看到的是片段 B 中的视图是单独动画的,TextView以与列表项 1 副标题不同的速度滑入,而列表项 1 标题和图标在没有动画的情况下立即出现,我希望整个视图同时动画化,这可能实现吗?

    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    Fragment existing = fragmentManager.findFragmentById(R.id.welcome_content);
    if (existing != null) {                
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            fragmentToLoad.setAllowEnterTransitionOverlap(true);                    
            fragmentToLoad.setEnterTransition(new Slide(Gravity.RIGHT));
        }
        fragmentTransaction.remove(existing);
    }
    fragmentTransaction.add(R.id.welcome_content, fragmentToLoad);
    fragmentTransaction.commitNow();

android:transitionGroup="true"应用于FragmentB的根布局。

来自ViewGroup#setTransitionGroup(boolean)文档:

更改在活动转换期间是否应将此ViewGroup视为单个实体。如果falseViewGroup不会转换,只会转换它的子级。如果true,整个ViewGroup将一起过渡。

最新更新