arimorty / floatingsearchview

A search view that implements a floating search bar also known as persistent search
https://github.com/arimorty/floatingsearchview/blob/master/README.md
Apache License 2.0
3.54k stars 667 forks source link

Collapse / Hide Floatingsearchview #196

Closed shifatul-i closed 7 years ago

shifatul-i commented 7 years ago

Please take a look at Google Play Store (Top Chart) page I think this will be a great addition to the library to be able to Collapse / Hide Floatingsearchview

Below are some sample images

image

image

rayliverified commented 7 years ago

Implementing this requires a completely different library. Thankfully, what you are looking for already exists :D https://github.com/Mauker1/MaterialSearchView https://github.com/claudiodegio/MsvSearch https://material.uplabs.com/posts/searchview

Hope this helps :+1:

echthard commented 7 years ago

Just hide the toolbar when the searchview gets focus and show the toolbar again when it loses focus. I do this by animating the toolbar up and down. It's not that hard.


    public void hideToolbar() {
        final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mToolbar.getLayoutParams();
        ValueAnimator animator = ValueAnimator.ofInt(params.topMargin, -mToolbar.getHeight());
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                params.topMargin = (Integer) valueAnimator.getAnimatedValue();
                mToolbar.requestLayout();
            }
        });
        animator.setDuration(Constants.MOVE_ANIMATION_DURATION);
        animator.start();

    }

    public void showToolbar() {
        final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mToolbar.getLayoutParams();
        ValueAnimator animator = ValueAnimator.ofInt(params.topMargin, 0);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                params.topMargin = (Integer) valueAnimator.getAnimatedValue();
                mToolbar.requestLayout();
            }
        });
        animator.setDuration(Constants.MOVE_ANIMATION_DURATION);
        animator.start();
    }