您的位置:首页 > 其它

ListView hide the part of headerView

2015-04-02 16:59 274 查看
private int measureHeight;  

private float lastY = 0; 

    @Override  

    public boolean dispatchTouchEvent(MotionEvent event) {  

        final int action = event.getAction();  

        if (null == mLinearLayout) {  

            return super.dispatchTouchEvent(event);  

        }  

  

        float y = event.getY();  

        int mHeight = mLinearLayout.getHeight();  

        switch (action) {  

        case MotionEvent.ACTION_DOWN:  

            if (measureHeight == 0) {  

                measureHeight = mLinearLayout.getHeight();  

            }  

            break;  

        case MotionEvent.ACTION_MOVE:  

            if (mListView.getFirstVisiblePosition() <= 0  

                    || (mListView.getFirstVisiblePosition() > 0 && mHeight > 0)) {  

                if (lastY == 0) {  

                    lastY = y;  

                }  

                float diffY = y - lastY;  

  

                int offset = 0;  

                if (diffY < 0 && mHeight > 0 && mHeight <= measureHeight) {  

                    float scrollY = diffY - (measureHeight - mHeight);  

                    offset = (int) (Math.abs(scrollY) <= measureHeight ? scrollY : -measureHeight);  

                    mLinearLayout.setPadding(0, offset, 0, 0);  

                }  

  

                if (diffY > 0 && mHeight <= measureHeight) {  

                    float scrollY = diffY - measureHeight + mHeight;  

                    offset = (int) (Math.abs(scrollY + measureHeight) <= measureHeight ? scrollY  

                            : 0);  

                    mLinearLayout.setPadding(0, offset, 0, 0);  

                }  

            }  

            break;  

        case MotionEvent.ACTION_UP:  

            lastY = 0;  

            break;  

        default:  

            return super.dispatchTouchEvent(event);  

        }  

        return super.dispatchTouchEvent(event);  

    }  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: