I am using a TabLayout with 5 different fragments. On 3 of these fragments a android.support.design.widget.FloatingActionButton
should appear. Right now I simply set the visibility of the FAB when the tab changes, but I would like to have an animation, where the FAB comes in and out.
How can I achieve this in Android?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
The hide/show animation for shrink/pop are automatically handled by the new version of the Support Library.(22.2.1) Then OnTabChange listener show or hide the floating action button using show/hide methods provided by the new library.
fab.show(); or fab.hide();
The design support library revision 22.2.1 (July 2015) added the
hide()
andshow()
methods to theFloatingActionButton
class, so you can use these from now on.http://developer.android.com/tools/support-library/index.html
Because I did not want to extend the
FloatingActionButton
, I made it this way:You want something like this? But instead of animating it on
onScrollListener
you can animate it ononCreateView
oronCreate
method. Follow this --> Implement Floating Action Button – Part 2Basically the code sums up only to this
Animate to Hide
and
Animate back to Show
but we dont want it to animate just to hide it so, 'Animate to Hide' will just be something like this
On 'Animate to Hide' put that on the
onCreateView
oronCreate
method so that on your FAB is hidden when you create this fragment and you could then add a handler and runnable that will trigger 'Animate back to Show' after a second or two to show your animationor you could use a time for short animations
I tried this one on onScroll but haven't tried on
onCreateView
oronCreate
but I guess it should work--EDIT--
Try this code ;)
The easiest way is to extend the FloatingActionButton class and override setVisibility. Like this:
The code above is taken from the Button class from my library. You can find sample implementations in sources.