开发者

ListView OverScroll

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.


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


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)
            {
            }

        });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜