Code example for RelativeLayout

Methods: getBottom, getPaddingBottom, getPaddingLeft, getPaddingRight, getTop, setPadding

0
            case MotionEvent.ACTION_UP:
                if (!isVerticalScrollBarEnabled()) {
                    setVerticalScrollBarEnabled(true);
                } 
                if (getFirstVisiblePosition() == 0 && mRefreshState != REFRESHING) {
                    if ((mRefreshView.getBottom() >= mRefreshViewHeight
                            || mRefreshView.getTop() >= 0)
                            && mRefreshState == RELEASE_TO_REFRESH) {
                        // Initiate the refresh 
                        mRefreshState = REFRESHING;
                        prepareForRefresh(); 
                        onRefresh(); 
                    } else if (mRefreshView.getBottom() < mRefreshViewHeight
                            || mRefreshView.getTop() <= 0) {
                        // Abort refresh and scroll down below the refresh view 
                        resetHeader(); 
                        setSelection(1);
                    } 
                } 
                break; 
            case MotionEvent.ACTION_DOWN:
                mLastMotionY = y;
                break; 
            case MotionEvent.ACTION_MOVE:
                applyHeaderPadding(event);
                break; 
        } 
        return super.onTouchEvent(event);
    } 
 
    private void applyHeaderPadding(MotionEvent ev) {
        // getHistorySize has been available since API 1 
        int pointerCount = ev.getHistorySize();
 
        for (int p = 0; p < pointerCount; p++) {
            if (mRefreshState == RELEASE_TO_REFRESH) {
                if (isVerticalFadingEdgeEnabled()) {
                    setVerticalScrollBarEnabled(false);
                } 
 
                int historicalY = (int) ev.getHistoricalY(p);
 
                // Calculate the padding to apply, we divide by 1.7 to 
                // simulate a more resistant effect during pull. 
                int topPadding = (int) (((historicalY - mLastMotionY)
                        - mRefreshViewHeight) / 1.7);
 
                mRefreshView.setPadding(
                        mRefreshView.getPaddingLeft(),
                        topPadding,
                        mRefreshView.getPaddingRight(),
                        mRefreshView.getPaddingBottom());
            } 
        } 
    } 
 
    /** 
     * Sets the header padding back to original size. 
     */ 
    private void resetHeaderPadding() { 
        mRefreshView.setPadding(
                mRefreshView.getPaddingLeft(),
                mRefreshOriginalTopPadding,
                mRefreshView.getPaddingRight(),
                mRefreshView.getPaddingBottom());
    } 
 
    /** 
     * Resets the header to the original state. 
     */ 
Experience pair programming with AI  Get Codota for Java