Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide and show fab within a coordinatorlayout? #4

Open
MohsenShafiee opened this issue Sep 23, 2015 · 1 comment
Open

hide and show fab within a coordinatorlayout? #4

MohsenShafiee opened this issue Sep 23, 2015 · 1 comment

Comments

@MohsenShafiee
Copy link

hi
Thanks for this beautiful library 👍
is it possible to hide and show fab inside coordinatorLayout and NestedScrollView when the scroll... i mean without any list scrolling!
thanks again...

@ghost
Copy link

ghost commented Oct 4, 2015

@TheLoyalCruel
You can just toggle view visibility to show or hide it. If you want to animate it you can use your own animation on the FAB or use predefined one like in the code below, where ANIMATION_DURATION is the duartion of expand/contract animation (default 400).

if(mFabToolbar.isFabExpanded()) {
    mFabToolbar.contractFab();
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            mFabToolbar.slideOutFab();
        }
    }, ANIMATION_DURATION);
} else {
    mFabToolbar.slideOutFab();
}

However, in my opinion it would be better to create your own animation to hide it in this scenario. Something like shriniking or sliding out to one of the sides, depending on why do you want to hide your FAB in the first place, would be prefferable over sliding it out to the bottom, when you don't have a scroll functionality. One way would be to create an ObjectAnimator. The code for shrinking would look something like this.

Animator hide = ObjectAnimator.ofPropertyValuesHolder(mFab,
        PropertyValuesHolder.ofFloat("scaleX", 1f, 0f),
        PropertyValuesHolder.ofFloat("scaleY", 1f, 0f));
hide.setDuration(250);

if(mFabToolbar.isFabExpanded()) {
    mFabToolbar.contractFab();
    hide.setStartDelay(ANIMATION_DURATION);
}

hide.start();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant