예제로 알려주는 글
Fragment 변경시 animation
Fragment 를 replace 하는 주변(?)에 변환(transition) 과 관계된 animation 을 set 해주면 된다.
부분이 animation 을 위해 set 해준 부분이다.
/** * A placeholder fragment containing a simple view. */ @SuppressLint("ValidFragment") public class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Title of Recent Pods Grid View podsView = rootView.findViewById(R.id.rl_recent_pods); podsView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Title of Recent Pods Grid PodListFragment podListFragment = new MainActivity.PodListFragment(); replaceFragment(v, R.id.rl_container_main, podListFragment, "tag_podlist"); } }); podsView.setTransitionName(Integer.toString(R.id.rl_recent_pods)); return rootView; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } /** * @param newFragment : new fragment which will be injected */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void replaceFragment(View view, int containerId, PodListFragment newFragment, String tag) { // Set shared and scene transitions setSharedElementReturnTransition( TransitionInflater.from(getActivity()).inflateTransition(R.transition.trans_move)); setExitTransition(TransitionInflater.from(getActivity()).inflateTransition(android.R.transition.explode)); // Set shared and scene transitions on 2nd fragment newFragment.setSharedElementEnterTransition(TransitionInflater.from(getActivity()).inflateTransition(R.transition.trans_move)); newFragment.setEnterTransition(TransitionInflater.from(getActivity()).inflateTransition(android.R.transition.explode)); newFragment.setId(view.getTransitionName()); android.support.v4.app.FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); trans.replace(containerId, newFragment, tag); trans.addToBackStack(null); trans.addSharedElement(view, view.getTransitionName()); trans.commit(); } } /** * A podlist fragment containing a simple view. */ public static class PodListFragment extends Fragment { private String id; public PodListFragment() { } @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_podlist, container, false); rootView.findViewById(R.id.ll_podlist).setTransitionName(id); return rootView; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } public void setId(String id){ this.id = id; } }
Activity transition animation
- Material World - Animating L: Shared View Activity Animations | WillowTree Development Blog
- Introduction to the New Lollipop Activity Transitions - Tuts+ Code Tutorial
See Also
Activity Animation
transition 을 이용한 animation 은 아래 글을 참고하자.- overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left)
보통 위의 함수를 사용하는데, 위의 경우는
- 새롭게 만들어지는 Activity 는 slide_in_left 로 들어오고, 자신은 slide_out_left 로 사라진다.
는 뜻이다. 만약 '0' 을 넣으면 animation 이 없다는 표시인데, 다른 Activity 가 animation 이 되는 동안 그냥 어두운 화면이 된다.
References
- 내부동작 소개 :Shared Element Transitions In-Depth (part 3a) | Android Design Patterns
- Animate ImageView between two activities using shared element transitions with ChangeImageTransform
댓글 없음:
댓글 쓰기