124697
124697

Reputation: 21893

How can I hide tabs while scrolling down a ListView then show them again if the user scrolls up?

I want to make the tabs of a tabhost fade up if the user is scrolling down a listview

I have the following code but it does not work

ListView ls = (ListView) findViewById(R.id.list);
        ls.setOnScrollListener(new OnScrollListener() {
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }
            int previousVisible = 3;
            public void onScroll(AbsListView view, int firstVisibleItem,
                    int visibleItemCount, int totalItemCount) {
                if (previousVisible < firstVisibleItem) {
                    getParent().findViewById(android.R.id.tabhost)
                            .setVisibility(View.INVISIBLE);
                } else {
                    getParent().findViewById(android.R.id.tabhost)
                            .setVisibility(View.VISIBLE);
                }
                previousVisible = firstVisibleItem;
            }
        });

Upvotes: 1

Views: 5112

Answers (1)

Glenn Bech
Glenn Bech

Reputation: 6182

Lars Werkman has implemented an Android Library to implement this UI principle from Roman Nurik and Nick Butcher.

https://github.com/LarsWerkman/QuickReturnListView

Upvotes: 1

Related Questions