How to hide tabhost on scroll top or down

959 Views Asked by At

In my application, It have tab at bottom and its content with in fragment. I want to fade in and fade out my bottom tab while user scroll up and down.

Please give me a tutorial link if you have.

Thank you

1

There are 1 best solutions below

0
On

Here is one not very elegant, but simple way.

yourScrollableView is a View which user will scroll, viewYouNeedToHide is a View which contains your tabs, REQUIRED_SWIPE is scroll distance which show/hide event will be sensitive to.

yourScrollableView.setOnTouchListener(new View.OnTouchListener() {

    float mY;
    float swipeDistance;
    final float REQUIRED_SWIPE = 50;

    @Override
    public boolean onTouch(View v, MotionEvent event) {
    float y = event.getY();

    switch(event.getAction()) {

        case MotionEvent.ACTION_DOWN :
            swipeDistance = 0;
            mY = y;
            break;

        case MotionEvent.ACTION_MOVE :
            swipeDistance += y - mY;
            if(Math.abs(swipeDistance) > REQUIRED_SWIPE) {
                if(swipeDistance < 0) {
                    if(viewYouNeedToHide.getVisibility() == View.VISIBLE) {
                        TranslateAnimation animate = new TranslateAnimation(
                                0,0,0,viewYouNeedToHide.getHeight());
                        animate.setDuration(500);
                        animate.setFillAfter(false);
                        viewYouNeedToHide.startAnimation(animate);
                        viewYouNeedToHide.setVisibility(View.GONE);
                        swipeDistance = 0;
                    }
                } else {
                    if(viewYouNeedToHide.getVisibility() != View.VISIBLE) {
                        TranslateAnimation animate = new TranslateAnimation(
                                0,0,viewYouNeedToHide.getHeight(),0);
                        animate.setDuration(500);
                        animate.setFillAfter(false);
                        viewYouNeedToHide.startAnimation(animate);
                        viewYouNeedToHide.setVisibility(View.VISIBLE);
                        swipeDistance = 0;
                    }
                }
            }

            mY = y;
            break;

    }

    mY = y;
    return false;

    }
});