列表视图滚动

发布于 2024-12-04 12:36:27 字数 274 浏览 1 评论 0原文

我正在填充一个 listView,然后我想做一些奇特的事情。 我尝试向列表添加一个 OverScroll 标题,我期望的效果是,如果我过度滚动列表,则可绘制对象将显示在列表顶部,因此过度滚动标题看起来像列表的隐藏标题。

我在布局 xml 文件中设置了 overScrollHeader 和 overScrollMode,但是没有任何改变。我在 Nexus S 上做到了这一点。

那么我对 overScrollHeader 有何期望以及如何使其发挥作用?

如果有人能帮助我,我将非常感激。

I am filling a listView, then I wanted to do something fancy.
I tried to add an OverScroll Header to the list, the effect I expected is that if I overscroll the list, a drawable will show up on top of the list, so the overscroll header looks like a hidden header for the list.

I set the overScrollHeader and overScrollMode in the layout xml file, however nothing changed. I did it on Nexus S.

So what can I expect from the overScrollHeader and how to make it work?

i will really appreciate it if someone can help me out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

第几種人 2024-12-11 12:36:27

您可以检查 https://jasonfry.co.uk/blog/android-overscroll-重新审视/。但它不适用于 Android 版本 < 2.3.

You can check https://jasonfry.co.uk/blog/android-overscroll-revisited/. However it doesn't work for android versions < 2.3.

挽心 2024-12-11 12:36:27
1) create a layout above your listview and status of this layout is gone (here is rlSearch)
2) in your activity, in action scroll, you get action motionEvent and check if listview is on the top and scroll down, you visible gone layout. here is my example and it work for me.
  listView.setOnScrollListener(new AbsListView.OnScrollListener()
        {
            boolean isScrollDown;
            float firstPosition = -1;

            @Override
            public void onScrollStateChanged(final AbsListView view, int scrollState)
            {
                view.setOnTouchListener(new View.OnTouchListener()
                {
                    @Override
                    public boolean onTouch(View v, MotionEvent event)
                    {
                        if (firstPosition == -1)
                        {
                            firstPosition = event.getRawY();
                            return false;
                        }
                        if (event.getRawY() > firstPosition && view.getFirstVisiblePosition() == 0)
                        {
                            isScrollDown = true;
                            firstPosition = -1;
                            rlSearch.setVisibility(View.VISIBLE);
                            return false;
                        }
                        if (event.getRawY() < firstPosition)
                        {
                            isScrollDown = false;
                            firstPosition = -1;
                            rlSearch.setVisibility(View.GONE);
                            return false;
                        }
                        return false;
                    }
                });
            }

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

        });
1) create a layout above your listview and status of this layout is gone (here is rlSearch)
2) in your activity, in action scroll, you get action motionEvent and check if listview is on the top and scroll down, you visible gone layout. here is my example and it work for me.
  listView.setOnScrollListener(new AbsListView.OnScrollListener()
        {
            boolean isScrollDown;
            float firstPosition = -1;

            @Override
            public void onScrollStateChanged(final AbsListView view, int scrollState)
            {
                view.setOnTouchListener(new View.OnTouchListener()
                {
                    @Override
                    public boolean onTouch(View v, MotionEvent event)
                    {
                        if (firstPosition == -1)
                        {
                            firstPosition = event.getRawY();
                            return false;
                        }
                        if (event.getRawY() > firstPosition && view.getFirstVisiblePosition() == 0)
                        {
                            isScrollDown = true;
                            firstPosition = -1;
                            rlSearch.setVisibility(View.VISIBLE);
                            return false;
                        }
                        if (event.getRawY() < firstPosition)
                        {
                            isScrollDown = false;
                            firstPosition = -1;
                            rlSearch.setVisibility(View.GONE);
                            return false;
                        }
                        return false;
                    }
                });
            }

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

        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文