<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_email_white_24dp"
android:layout_gravity="bottom|end"
android:layout_marginEnd="16dp"
android:layout_marginBottom="180dp"
fab:backgroundTint="@color/colorAccent"
android:visibility="invisible"
fab:pressedTranslationZ="12dp"
android:elevation="6dp"
android:id="@+id/fabMsg"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_thumb_up_white_24dp"
android:layout_gravity="bottom|end"
android:layout_marginEnd="16dp"
android:layout_marginBottom="100dp"
fab:backgroundTint="@color/colorPrimary"
android:visibility="invisible"
fab:pressedTranslationZ="12dp"
android:elevation="6dp"
android:id="@+id/fabThumb"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_white_24dp"
android:layout_gravity="bottom|end"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
fab:pressedTranslationZ="12dp"
android:elevation="6dp"
android:visibility="invisible"
android:id="@+id/fabMain"/>
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
android:duration="300"
android:fromXScale="0.8"
android:fromYScale="0.8"
android:toXScale="0.0"
android:toYScale="0.0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"/>
<alpha
android:duration="300"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<rotate
android:duration="300"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="45" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<rotate
android:duration="300"
android:fromDegrees="45"
android:toDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotY="50%"
android:pivotX="50%"
/>
</set>
public class MainActivity extends AppCompatActivity {
private static final int LAYOUT = R.layout.activity_main;
Animation FabOpen, FabClose, FabRClockwise, FabRanticlockWise;
private FloatingActionButton fabMain, fabMsg, fabThumb;
boolean isOpen = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(LAYOUT);
FabOpen = AnimationUtils.loadAnimation(
getActivity().getApplicationContext(), R.anim.fab_open);
FabClose = AnimationUtils.loadAnimation(
getActivity().getApplicationContext(), R.anim.fab_close);
FabRClockwise = AnimationUtils.loadAnimation(
getActivity().getApplicationContext(), R.anim.rotate_clockwise);
FabRanticlockWise = AnimationUtils.loadAnimation(
getActivity().getApplicationContext(), R.anim.rotate_anticlockwise);
fabMain = (FloatingActionButton) view.findViewById(R.id.fabMain);
fabMsg = (FloatingActionButton) view.findViewById(R.id.fabMsg);
fabThumb = (FloatingActionButton) view.findViewById(R.id.fabThumb);
fabMain.setOnClickListener(clickListener);
fabMsg.setOnClickListener(clickListener);
fabThumb.setOnClickListener(clickListener);
}
View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.fabMain :
if (!isOpen) {
fabThumb.startAnimation(FabOpen);
fabMsg.startAnimation(FabOpen);
fabMain.startAnimation(FabRClockwise);
fabThumb.setClickable(true);
fabMsg.setClickable(true);
isOpen = true;
} else {
fabThumb.startAnimation(FabClose);
fabMsg.startAnimation(FabClose);
fabMain.startAnimation(FabRanticlockWise);
fabThumb.setClickable(false);
fabMsg.setClickable(false);
isOpen = false;
}
break;
}
}
};
}