1

I am trying to implement sort of collpasing toolbar - but without the toolbar(instead of the toolbar it would be a dropdown element, which is essentially a RelativeLayout that has LinearLayout right beneath (the expanded items in the dropdown) that is hovering over the whole layout once the dropdown is pressed.

I thought about implementing a collapsing toolbar and putting the drop down inside the toolbar, but that probably won't be a good idea since a drop down is not a static component like an imageview for example. I also use ActionBar in my app, so migrating to Toolbar will most likely be very time-consuming, not to mention all the technical issues that come with it.

Aside from that, I thought about detecting a movement/scrolling direction in the listview, and then hide/show the drop down, but it is very buggy when I simply hold my finger on the list view ( it goes mad and switches from up to down and vice versa very very quickly and doesn't stop until I lift the finger).

Are there any other options to implement this sort of behavior? enter image description here

BVtp
  • 2,308
  • 2
  • 29
  • 68

2 Answers2

0

ListView has a default scrollListener. You can use it to know if it's scrolling or not. then hide the dropDown!

        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
                    @Override
                    public void onScrollStateChanged(AbsListView absListView, int i) {

    //detect stop. have a counter then view the dropDown

                    }

                    @Override
                    public void onScroll(AbsListView absListView, int i, int i1, int i2) {

    //Hide dropDown

@Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {

            if(mLastFirstVisibleItem<firstVisibleItem)
            {
                Log.i("SCROLLING DOWN","TRUE");
            }
            if(mLastFirstVisibleItem>firstVisibleItem)
            {
                Log.i("SCROLLING UP","TRUE");
            }
            mLastFirstVisibleItem=firstVisibleItem;

        }
                    }
                });
Sadiq Md Asif
  • 882
  • 6
  • 18
  • but I need to know the direction. Otherwise I wouldn't know whether to hide to show the dropdown – BVtp Jan 10 '17 at 08:29
  • alright, funtionality-wise it works. However, even with my animation of collpasing/expanding the dropdown element it seems like it disappears and appears all of a sudden.. Could you please give an example how to make it smoother? like in a collapsing toolbar – BVtp Jan 10 '17 at 08:41
  • Use animation - http://stackoverflow.com/questions/23925907/slidedown-and-slideup-layout-with-animation-android – Leśniakiewicz Jan 10 '17 at 08:56
0

I'm very curious about what others propose, because I fight with that some time ago. Finnaly I'm detecting movement/scrolling direction in the listview, and then hide/show the header (as you mention). I did it like this (and I don't have bugs):

listView.setOnScrollListener(OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

            final int currentFirstVisibleItem = view.getFirstVisiblePosition();

            if (currentFirstVisibleItem > mLastFirstVisibleItem) header.setVisibility(View.GONE);
            else if (currentFirstVisibleItem < mLastFirstVisibleItem) header.setVisibility(View.VISIBLE);

            mLastFirstVisibleItem = currentFirstVisibleItem;
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        }
    });

I the end I made header to show/hide with animation.

Leśniakiewicz
  • 874
  • 1
  • 10
  • 21
  • what if you start scrolling, but then you hold your finger in one place, and don't lift it. Doesn't it switch rapidly between down-up endlessly until you lift your finger? It does so in my case – BVtp Jan 10 '17 at 08:31