Skip to content Skip to sidebar Skip to footer

How To Hide And Show A Layout On Scrolling Down A Scroll View In Android?

I have a particular layout which consist a scroll view and an image which is at bottom of the activity. My question is that when I start scrolling up that image will not visible an

Solution 1:

You can achieve this easily with android support widget CoordinatorLayout. Follow this post to hide/show the image based on scrolling.

You can learn more about coordinator layout here

Solution 2:

    scrollView.getViewTreeObserver().addOnScrollChangedListener(newViewTreeObserver.OnScrollChangedListener() {
    @OverridepublicvoidonScrollChanged() {
        if (scrollView != null) {
            if (scrollView.getChildAt(0).getBottom() <= (scrollView.getHeight() + scrollView.getScrollY())) {
                relativeLayout.setVisibility(View.VISIBLE);
            }
            else {
                relativeLayout.setVisibility(View.INVISIBLE);
            }
        }
    }
});

Solution 3:

Here is something that you should try out

ScrollViewsv= (ScrollView)findViewById(R.id.scrl);
sv.scrollTo(0, sv.getTop());

and when it gets to top show the visibility of the image view as visible and in else part make it gone...

Post a Comment for "How To Hide And Show A Layout On Scrolling Down A Scroll View In Android?"