allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.rjsvieira:FloatingMenuButton:1.0.0'
}
The FloatingMenuButton central image allows the user to give it any appearance he desires.
The user can also specify a ClickListener and add it to it. Thanks to the FloatingMenuButton's composite clickListener, it will not override the animation toggling.
The FloatingMenuButton only accepts FloatingSubButton children.
Like the FloatingMenuButton, the FloatingSubButton can be configured to have a specific background and a ClickListener for interaction.
The following XML file specifies the example on the radial gifs :
<rjsv.FloatingMenuButton.FloatingMenuButton.FloatingMenuButton
android:id="@+id/my_floating_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:scaleType="centerInside"
circleview:layout_constraintBottom_toBottomOf="parent"
circleview:layout_constraintLeft_toLeftOf="parent"
circleview:layout_constraintRight_toRightOf="parent"
circleview:layout_constraintTop_toTopOf="parent"
FloatingMenuButtonActionButton:animationType="radial"
FloatingMenuButtonActionButton:dispositionEndAngle="360"
FloatingMenuButtonActionButton:dispositionStartAngle="0"
FloatingMenuButtonActionButton:subActionButtonRadius="100">
<rjsv.FloatingMenuButton.FloatingMenuButton.subbutton.FloatingSubButton
android:id="@+id/sub_button_1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/one"/>
<rjsv.FloatingMenuButton.FloatingMenuButton.subbutton.FloatingSubButton
android:id="@+id/sub_button_2"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/two"/>
<rjsv.FloatingMenuButton.FloatingMenuButton.subbutton.FloatingSubButton
android:id="@+id/sub_button_3"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/three"/>
<rjsv.FloatingMenuButton.FloatingMenuButton.subbutton.FloatingSubButton
android:id="@+id/sub_button_4"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/four"/>
<rjsv.FloatingMenuButton.FloatingMenuButton.subbutton.FloatingSubButton
android:id="@+id/sub_button_5"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/five"/>
</rjsv.FloatingMenuButton.FloatingMenuButton.FloatingMenuButton>
Attribute | Type | Default | Default |
---|---|---|---|
startAngle | int | The starting angle for button disposition | 0 |
endAngle | int | The ending angle for button disposition | 180 |
radius | int | The distance between the central button and its children | 100(dp) |
animationType | AnimationType (Enumerator) | The open/close animation for FloatingMenuButton | AnimationType.EXPAND |
openingDuration | int | The opening duration, in milliseconds, of the animation | 500 |
closingDuration | int | The closing duration, in milliseconds, of the animation | 500 |
lagBetweenItems | int | The lag duration between animating items. Affects only AnimationType.EXPAND | 100 |
openingInterpolator | Interpolator | The opening interpolator. Allows different rythms on the animations | OvershootInterpolator |
closingInterpolator | Interpolator | The closing interpolator. Allows different rythms on the animations | AccelerateDecelerateInterpolator |
shouldRotate | boolean | Specify whether the items should rotate while animating. Available only in AnimationType.EXPAND | true |
shouldFade | boolean | Specify whether the items should fade while animating. Available only in AnimationType.EXPAND | true |
shouldScale | boolean | Specify whether the items should scale while animating. Available only in AnimationType.EXPAND | true |
You can track whether the FloatingMenuButton is in open or closed status
public interface FloatingMenuButtonStateChangeListener {
void onMenuOpened(FloatingMenuButton menu);
void onMenuClosed(FloatingMenuButton menu);
}
You can configure the FloatingMenuButton programmatically rather than xml, specifying and settings its variables. Consider the following example :
floatingButton = (FloatingMenuButton) findViewById(R.id.my_floating_button);
floatingButton.setStartAngle(0)
.setEndAngle(360)
.setAnimationType(AnimationType.EXPAND);
floatingButton.getAnimationHandler()
.setOpeningAnimationDuration(500)
.setClosingAnimationDuration(200)
.setLagBetweenItems(0)
.setOpeningInterpolator(new FastOutSlowInInterpolator())
.setClosingInterpolator(new FastOutLinearInInterpolator())
.shouldFade(true)
.shouldScale(true)
.shouldRotate(false)
;