其他分享
首页 > 其他分享> > android-使片段过渡同时为动画视图

android-使片段过渡同时为动画视图

作者:互联网

我用片段B替换了片段A并对其进行了动画处理.片段B具有带有TextView和ListView的RelativeLayout.我所看到的是片段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的根布局.

docs of ViewGroup#setTransitionGroup(boolean)开始:

Changes whether or not this ViewGroup should be treated as a single entity during Activity Transitions. If false, the ViewGroup won’t transition, only its children. If true, the entire ViewGroup will transition together.

标签:android-fragments,android-animation,android-transitions,fragment-transitions,and
来源: https://codeday.me/bug/20191110/2015005.html