0

I have a screen as shown in below screenshot. I have a category consisting of "Vegetables", "Fruits" and "Snacks" which is shown at top via a card view. Now what I want is to hide this portion while scrolling down and show it only when scrolling up.

How do I do this?

[Additional Info: For the products scrolling, "Scroll view" is used. Also this entire screen is a fragment.]

enter image description here

milan m
  • 2,164
  • 3
  • 26
  • 40

2 Answers2

0

u can pass the cardview view in a method which checks if the view hits the scrollview bounds. This post might help Android: how to check if a View inside of ScrollView is visible?

Community
  • 1
  • 1
AbiDoll
  • 106
  • 5
  • No. We are using a scroll view. In it there is a linear layout and the whole screen is generated dynamically. – milan m Aug 04 '16 at 10:06
0

You can show and hide your cardview in listView onScrollListener.See this method it migh be helpful.

 private int mLastFirstVisibleItem;
 private ListView listView;

 listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (view.getId() == listView.getId()) {
                final int currentFirstVisibleItem = listView.getFirstVisiblePosition();

                if (currentFirstVisibleItem > mLastFirstVisibleItem) {
                    cardView.setVisibility(View.GONE);
                } else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
                    cardView.setVisibility(View.VISIBLE);
                }
                mLastFirstVisibleItem = currentFirstVisibleItem;

            }

        }
sumit singh
  • 588
  • 1
  • 5
  • 20