我正在用片段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
的根布局。
来自ViewGroup#setTransitionGroup(boolean)
文档:
更改在活动转换期间是否应将此
ViewGroup
视为单个实体。如果false
,ViewGroup
不会转换,只会转换它的子级。如果true
,整个ViewGroup
将一起过渡。