同时制作片段过渡动画视图
Make fragment transition animate views simultaneously
我正在用片段 B 替换片段 A 并制作动画。片段 B 有一个 RelativeLayout
,一个 TextView
和一个 ListView
。我可以看到片段 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.
我正在用片段 B 替换片段 A 并制作动画。片段 B 有一个 RelativeLayout
,一个 TextView
和一个 ListView
。我可以看到片段 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. Iffalse
, theViewGroup
won't transition, only its children. Iftrue
, the entireViewGroup
will transition together.