Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create floating action button transforming into a single sheet of material

I'm trying to see if any in-build animation exist on the design library to create floating action button transforming into single material sheet like shown in the material design image

https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B8v7jImPsDi-TjBicTdvQjg4M1E/components-buttons-fab-transition_card_02.webm

like image 773
Libin Avatar asked Oct 13 '15 02:10

Libin


People also ask

How do you make a floating action button?

Add the floating action button to your layoutThe size of the FAB, using the app:fabSize attribute or the setSize() method. The ripple color of the FAB, using the app:rippleColor attribute or the setRippleColor() method. The FAB icon, using the android:src attribute or the setImageDrawable() method.

How do I create an expandable floating action button on fab menu?

Designing Custom Expandable FAB After creating a new Android project, go to the drawable folder and import drawable icons from vector assets. These icons will be placed at the center of the FAB. To add icons, right-click on drawable , select new , then select Vector Asset and choose an icon from Clip Art .


1 Answers

Use MaterialContainerTransform from Material Components:

 private fun toggleFabMenu() {
        val views = listOf<View>(fab, menuView).sortedBy { !it.isVisible }

        val shareMenuTransform = MaterialContainerTransform().apply {
            startView = views.first()
            endView = views.last()           
            scrimColor = Color.TRANSPARENT
            duration = 500
                      
        }
        TransitionManager.beginDelayedTransition(root, shareMenuTransform)
        views.first().isVisible = false
        views.last().isVisible = true
    }

enter image description here

See docs for more details: https://material.io/develop/android/theming/motion

like image 147
deviant Avatar answered Oct 04 '22 08:10

deviant