我正在用 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. Iffalse
, theViewGroup
won't transition, only its children. Iftrue
, the entireViewGroup
will transition together.
关于android - 同时制作 fragment 过渡动画 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47270668/