android - 同时制作 fragment 过渡动画 View

标签 android android-fragments android-animation android-transitions fragment-transitions

我正在用 fragment B 替换 fragment A 并为其设置动画。 fragment B 有一个 RelativeLayout 和一个 TextView 和一个 ListView。我可以看到 fragment B 中的 View 是单独动画的,TextView 以不同于列表项 1 副标题的速度滑入,而列表项 1 标题和图标立即出现而没有动画,我希望整个 View 同时具有动画效果,这有可能实现吗?

    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 - 同时制作 fragment 过渡动画 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47270668/

相关文章:

安卓通知错误

java - 使用 Android 下载文件,并在 ProgressDialog 中显示进度

android - 在 fragment 中单击按钮后填充 ListView

android - 在android View 中闪烁文本

android - Fragment 动画后的致命信号 11

android - 将 HTML 数据加载到 WebView 中,引用本地镜像?

android - 使用android sdk而不是Share Intent在Google Plus上分享照片

java - Android: fragment *.post() 中的处理程序?

java - ViewPager不显示Fragment

android - 垂直旋转 ImageView