Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android scroll up hide view and scroll down show view effect like twitter

How to do scrolling effect like twitter when scroll Up hide viewpager tab (Home, Discover, activity). Or effect like facebook scrolling, while scroll up hide option view(status, photo, checkin) when scroll down show option view. Any example link will do please help.

like image 438
NaiveBz Avatar asked Feb 17 '14 08:02

NaiveBz


People also ask

What is overscroll in Android?

Overscrolling effects indicate that the user has reached the end of a scrollable list or page.


1 Answers

Easy solution:

public abstract class OnScrollObserver implements AbsListView.OnScrollListener {

public abstract void onScrollUp();

public abstract void onScrollDown();

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}

int last = 0;
boolean control = true;

@Override
public void onScroll(AbsListView view, int current, int visibles, int total) {
    if (current < last && !control) {
        onScrollUp();
        control = true;
    } else if (current > last && control) {
        onScrollDown();
        control = false;
    }

    last = current;
}

Usage:

listView.setOnScrollListener(new OnScrollObserver() {
        @Override
        public void onScrollUp() {

        }

        @Override
        public void onScrollDown() {

        }
    });
like image 92
Vansuita Jr. Avatar answered Sep 21 '22 05:09

Vansuita Jr.