I am using a FloatingActionButton in my app. Occasionally, it overlaps essential content, so I would like to make it so the user can drag the FAB out of the way.
No drag and drop functionality, per se, is required. It just needs to be movable. The docs do not mention this, but I'm sure I've seen such functionality in other apps.
Can you anyone advise / provide a code snippet on how to do it (preferably in XML).
you can try like below by just impletementing
onTouch
on anyView
,xml
java
Try this:
And the XML:
You can make any View Draggable and Clickable.
So, you wanna create a Movable
FloatingActionButton
, huh?!Based on this answer for another SO question this is the code I have created. It seems to work nicely (with working click functionality) and isn't dependent on the FAB's parent layout or positioning...
And here is the XML...
Basically, you just need to replace
android.support.design.widget.FloatingActionButton
withcom.example.MovableFloatingActionButton
in your XML.