ListView OverScroll

*爱你&永不变心* 提交于 2019-12-22 05:20:50

问题


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.


回答1:


You can check http://jasonfry.co.uk/?id=27. However it doesn't work for android versions < 2.3.




回答2:


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

        });


来源:https://stackoverflow.com/questions/7423912/listview-overscroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!