简体   繁体   English

向下滚动时隐藏名片视图,向上滚动时显示

[英]Hide card view while scrolling down and show when scrolling up

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.] 另外,整个屏幕都是碎片。]

在此处输入图片说明

u can pass the cardview view in a method which checks if the view hits the scrollview bounds. 您可以通过一种方法通过cardview视图,该方法可以检查视图是否达到scrollview边界。 This post might help Android: how to check if a View inside of ScrollView is visible? 这篇文章可能对Android有帮助:如何检查ScrollView内部的View是否可见?

You can show and hide your cardview in listView onScrollListener.See this method it migh be helpful. 您可以在listView onScrollListener上显示和隐藏cardview。请参见此方法。

 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;

            }

        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 向上/向下滚动时如何隐藏/显示视图? - How to hide/show view when scrolling up/down? 在向上滚动时在ListView中显示Bottom Buttons Bar,在向下滚动时隐藏它 - Show Bottom Buttons Bar in ListView while scrolling up and hide when scrolling down Android:向上滚动时显示工具栏(向上拖动),向下滚动时隐藏(向下拖动) - Android: Show toolbar when scrolling UP(Drag UP) and hide when scrolling down(Drag down) 上下滚动时的Android隐藏和显示操作栏 - Android Hide and Show Actionbar when Scrolling up and down 如何在向下滚动时隐藏底部导航栏并在jetpack compose中向上滚动时显示它? - How to hide bottom navigation bar while scrolling down and show it while scrolling up in jetpack compose? 上下滚动后无法隐藏视图 - Unable To Hide view after Scrolling up and Down 向上滚动时隐藏顶部布局,向下滚动时显示顶部布局(例如collapsingToolbarLayout) - Hide top layout on scrolling up and show on scrolling down (like collapsingToolbarLayout) 如何在向下滚动ListView时隐藏标签,然后在用户向上滚动时再次显示它们? - How can I hide tabs while scrolling down a ListView then show them again if the user scrolls up? Android:隐藏/显示页脚/页眉为向下/向上滚动scrollview - Android : hide/show footer/header as scrolling scrollview down/up 如何在Android中向下滚动滚动视图时隐藏和显示布局? - How to hide and show a layout on scrolling down a scroll view in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM