Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Practical Activity Transition in Android

Practical Activity Transition in Android

Avatar for punchdrunker

punchdrunker

March 08, 2019
Tweet

More Decks by punchdrunker

Other Decks in Programming

Transcript

  1. Fragment to Fragment ࣮૷ྫ ImageView transitioningView = view.findViewById(R.id.card_image); fragment.getFragmentManager() .beginTransaction()

    .setReorderingAllowed(true) // Optimize for shared element transition .addSharedElement( transitioningView, transitioningView.getTransitionName()) .replace( R.id.fragment_container, new ImagePagerFragment(), ImagePagerFragment.class.getSimpleName()) .addToBackStack(null) .commit();
  2. Activity to Activity transitionNameΛϖΞͰઃఆ͢Δͷ͸ಉ͡ɻ startActivityͷoptionͱͯ͠ɺsharedElementΛϖΞʹ ͨ͠bundleΛ౉͢ɻ ෳ਺౉͚ͨ͠Ε͹PairܕͰՄม௕Ҿ਺ͱͯ͠౉ͤΔɻ val intent =

    ToActivity.createIntent(context, position) val option = ActivityOptions.makeSceneTransitionAnimation( activity, view, getString(R.string.shared_element)).toBundle() startActivity(intent, option)
  3. AppBar/ϑολ͔ͿΔ໰୊ ্ԼʹॏͳΔView͕͋ͬͨΒεΫϩʔϧͰճආ private fun shoulScrollList(cell: View): Boolean { val cellLocation

    = IntArray(2) cell.getLocationOnScreen(cellLocation) val cellTop = cellLocation[1] val listLocation = IntArray(2) binding.list.getLocationOnScreen(listLocation) val diffToAppBar = cellTop - listLocation[1] val cellBottom = cellTop + binding.list.height val listBottom = listLocation[1] + binding.list.height val diffToBottom = cellBottom - listBottom return (diffToAppBar < 0 || diffToBottom > 0) }
  4. ίʔϧόοΫͰԿ͕ग़དྷΔ͔ ඥ෇͘SharedElementΛಈతʹมߋͰ͖Δ setExitSharedElementCallback(object : SharedElementCallback() { // names: List<String>, sharedElements:

    MutableMap<String, View> override fun onMapSharedElements(names: ..., sharedElements: ...) { val viewHolder = fromFragment?.getViewHolder(newPosition) val itemView = viewHolder?.itemView ?: return val photoView = itemView.findViewById<ImageView>(R.id.card_photo) sharedElements[names[0]] = photoView } })
  5. FIN