Fragment tricks
2017-12-02 本文已影响67人
yangweigbh
用户navigate forward的时候要保存back stack,让backstack去响应back button的点击

当要为fragment创建一个backstack栈时,需要执行多个transaction,这时需要执行setreorderingallowed(true),来优化transaction的执行(有些操作会被合并)。

Fragment transition
Basic transition:fade,open,close

custom animation

fragment中view的切换动画,在fragment上设置,setEnterTransition
对于非sharedElement生效。setSharedElementEnterTransition
对于shared element生效。在transaction中指定sharedelement。

当从detail view中返回recycler view中时,因为shared element还没有在RecyclerView还没有layout,所以要onCreateview
中调用postponeEnterTransition,然后监听layout完成后调用startPostponedEnterTransition,同时transaction还需要设置setreorderingallowed(true),因为enter和exit的fragment会同时存在。


不要在retain instance fragment中保存
- views
- contexts(activities)
- callback reference