Code example for RelativeLayout

Methods: getBottom, getPaddingBottom, getPaddingLeft, getPaddingRight, setPadding

0
     */ 
    public void onDropDownComplete() { 
        if (isDropDownStyle) { 
            setHeaderStatusClickToLoad(); 
 
            if (headerLayout.getBottom() > 0) { 
                invalidateViews(); 
                setSecondPositionVisible(); 
            } 
        } 
    } 
 
    /** 
     * on bottom begin, adjust view status 
     */ 
    private void onBottomBegin() { 
        if (isOnBottomStyle) { 
            if (isShowFooterProgressBar) { 
                footerProgressBar.setVisibility(View.VISIBLE); 
            } 
            footerButton.setText(footerLoadingText); 
            footerButton.setEnabled(false); 
        } 
    } 
 
    /** 
     * on bottom loading, you can call it by manual, but you should manual call onBottomComplete at the same time. 
     */ 
    public void onBottom() { 
        if (isOnBottomStyle && !isOnBottomLoading) { 
            isOnBottomLoading = true; 
            onBottomBegin(); 
            footerButton.performClick(); 
        } 
    } 
 
    /** 
     * on bottom load complete, restore view status 
     */ 
    public void onBottomComplete() { 
        if (isOnBottomStyle) { 
            if (isShowFooterProgressBar) { 
                footerProgressBar.setVisibility(View.GONE); 
            } 
            footerButton.setEnabled(true); 
            if (!hasMore) { 
                footerButton.setText(footerNoMoreText); 
            } else { 
                footerButton.setText(footerDefaultText); 
            } 
            isOnBottomLoading = false; 
        } 
    } 
 
    /** 
     * OnDropDownListener, called when header released 
     *  
     * @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2012-5-31 
     */ 
    public interface OnDropDownListener { 
 
        /** 
         * called when header released 
         */ 
        public void onDropDown(); 
    } 
 
    /** 
     * set second position visible(index is 1), because first position is header layout 
     */ 
    public void setSecondPositionVisible() { 
        if (getAdapter() != null && getAdapter().getCount() > 0 && getFirstVisiblePosition() == 0) { 
            setSelection(1); 
        } 
    } 
 
    /** 
     * set whether has more. if hasMore is false, onBottm will not be called when listView scroll to bottom 
     *  
     * @param hasMore 
     */ 
    public void setHasMore(boolean hasMore) { 
        this.hasMore = hasMore; 
    } 
 
    /** 
     * get whether has more 
     *  
     * @return 
     */ 
    public boolean isHasMore() { 
        return hasMore; 
    } 
 
    /** 
     * get header layout view 
     *  
     * @return 
     */ 
    public RelativeLayout getHeaderLayout() { 
        return headerLayout; 
    } 
 
    /** 
     * get footer layout view 
     *  
     * @return 
     */ 
    public RelativeLayout getFooterLayout() { 
        return footerLayout; 
    } 
 
    /** 
     * get rate about drop down distance and header padding top when drop down 
     *  
     * @return headerPaddingTopRate 
     */ 
    public float getHeaderPaddingTopRate() { 
        return headerPaddingTopRate; 
    } 
 
    /** 
     * set rate about drop down distance and header padding top when drop down 
     *  
     * @param headerPaddingTopRate 
     */ 
    public void setHeaderPaddingTopRate(float headerPaddingTopRate) { 
        this.headerPaddingTopRate = headerPaddingTopRate; 
    } 
 
    /** 
     * get min distance which header can release to loading 
     *  
     * @return headerReleaseMinDistance 
     */ 
    public int getHeaderReleaseMinDistance() { 
        return headerReleaseMinDistance; 
    } 
 
    /** 
     * set min distance which header can release to loading 
     *  
     * @param headerReleaseMinDistance 
     */ 
    public void setHeaderReleaseMinDistance(int headerReleaseMinDistance) { 
        this.headerReleaseMinDistance = headerReleaseMinDistance; 
    } 
 
    /*** 
     * get header default text, default is R.string.drop_down_list_header_default_text 
     *  
     * @return 
     */ 
    public String getHeaderDefaultText() { 
        return headerDefaultText; 
    } 
 
    /** 
     * set header default text, default is R.string.drop_down_list_header_default_text 
     *  
     * @param headerDefaultText 
     */ 
    public void setHeaderDefaultText(String headerDefaultText) { 
        this.headerDefaultText = headerDefaultText; 
        if (headerText != null && currentHeaderStatus == HEADER_STATUS_CLICK_TO_LOAD) { 
            headerText.setText(headerDefaultText); 
        } 
    } 
 
    /** 
     * get header pull text, default is R.string.drop_down_list_header_pull_text 
     *  
     * @return 
     */ 
    public String getHeaderPullText() { 
        return headerPullText; 
    } 
 
    /** 
     * set header pull text, default is R.string.drop_down_list_header_pull_text 
     *  
     * @param headerPullText 
     */ 
    public void setHeaderPullText(String headerPullText) { 
        this.headerPullText = headerPullText; 
    } 
 
    /** 
     * get header release text, default is R.string.drop_down_list_header_release_text 
     *  
     * @return 
     */ 
    public String getHeaderReleaseText() { 
        return headerReleaseText; 
    } 
 
    /** 
     * set header release text, default is R.string.drop_down_list_header_release_text 
     *  
     * @param headerReleaseText 
     */ 
    public void setHeaderReleaseText(String headerReleaseText) { 
        this.headerReleaseText = headerReleaseText; 
    } 
 
    /** 
     * get header loading text, default is R.string.drop_down_list_header_loading_text 
     *  
     * @return 
     */ 
    public String getHeaderLoadingText() { 
        return headerLoadingText; 
    } 
 
    /** 
     * set header loading text, default is R.string.drop_down_list_header_loading_text 
     *  
     * @param headerLoadingText 
     */ 
    public void setHeaderLoadingText(String headerLoadingText) { 
        this.headerLoadingText = headerLoadingText; 
    } 
 
    /** 
     * get footer default text, default is R.string.drop_down_list_footer_default_text 
     *  
     * @return 
     */ 
    public String getFooterDefaultText() { 
        return footerDefaultText; 
    } 
 
    /** 
     * set footer default text, default is R.string.drop_down_list_footer_default_text 
     *  
     * @param footerDefaultText 
     */ 
    public void setFooterDefaultText(String footerDefaultText) { 
        this.footerDefaultText = footerDefaultText; 
        if (footerButton != null && footerButton.isEnabled()) { 
            footerButton.setText(footerDefaultText); 
        } 
    } 
 
    /** 
     * get footer loading text, default is R.string.drop_down_list_footer_loading_text 
     *  
     * @return 
     */ 
    public String getFooterLoadingText() { 
        return footerLoadingText; 
    } 
 
    /** 
     * set footer loading text, default is R.string.drop_down_list_footer_loading_text 
     *  
     * @param footerLoadingText 
     */ 
    public void setFooterLoadingText(String footerLoadingText) { 
        this.footerLoadingText = footerLoadingText; 
    } 
 
    /** 
     * get footer no more text, default is R.string.drop_down_list_footer_no_more_text 
     *  
     * @return 
     */ 
    public String getFooterNoMoreText() { 
        return footerNoMoreText; 
    } 
 
    /** 
     * set footer no more text, default is R.string.drop_down_list_footer_no_more_text 
     *  
     * @param footerNoMoreText 
     */ 
    public void setFooterNoMoreText(String footerNoMoreText) { 
        this.footerNoMoreText = footerNoMoreText; 
    } 
 
    /** status which you can click to load, init satus **/ 
    public static final int HEADER_STATUS_CLICK_TO_LOAD     = 1; 
    /** 
     * status which you can drop down and then release to excute onDropDownListener, when height of header layout lower 
     * than a value 
     **/ 
    public static final int HEADER_STATUS_DROP_DOWN_TO_LOAD = 2; 
    /** status which you can release to excute onDropDownListener, when height of header layout higher than a value **/ 
    public static final int HEADER_STATUS_RELEASE_TO_LOAD   = 3; 
    /** status which is loading **/ 
    public static final int HEADER_STATUS_LOADING           = 4; 
 
    /** 
     * set header status to {@link #HEADER_STATUS_CLICK_TO_LOAD} 
     */ 
    private void setHeaderStatusClickToLoad() { 
        if (currentHeaderStatus != HEADER_STATUS_CLICK_TO_LOAD) { 
            resetHeaderPadding(); 
 
            headerImage.clearAnimation(); 
            headerImage.setVisibility(View.GONE); 
            headerProgressBar.setVisibility(View.GONE); 
            headerText.setText(headerDefaultText); 
 
            currentHeaderStatus = HEADER_STATUS_CLICK_TO_LOAD; 
        } 
    } 
 
    /** 
     * set header status to {@link #HEADER_STATUS_DROP_DOWN_TO_LOAD} 
     */ 
    private void setHeaderStatusDropDownToLoad() { 
        if (currentHeaderStatus != HEADER_STATUS_DROP_DOWN_TO_LOAD) { 
            headerImage.setVisibility(View.VISIBLE); 
            if (currentHeaderStatus != HEADER_STATUS_CLICK_TO_LOAD) { 
                headerImage.clearAnimation(); 
                headerImage.startAnimation(reverseFlipAnimation); 
            } 
            headerProgressBar.setVisibility(View.GONE); 
            headerText.setText(headerPullText); 
 
            if (isVerticalFadingEdgeEnabled()) { 
                setVerticalScrollBarEnabled(false); 
            } 
 
            currentHeaderStatus = HEADER_STATUS_DROP_DOWN_TO_LOAD; 
        } 
    } 
 
    /** 
     * set header status to {@link #HEADER_STATUS_RELEASE_TO_LOAD} 
     */ 
    private void setHeaderStatusReleaseToLoad() { 
        if (currentHeaderStatus != HEADER_STATUS_RELEASE_TO_LOAD) { 
            headerImage.setVisibility(View.VISIBLE); 
            headerImage.clearAnimation(); 
            headerImage.startAnimation(flipAnimation); 
            headerProgressBar.setVisibility(View.GONE); 
            headerText.setText(headerReleaseText); 
 
            currentHeaderStatus = HEADER_STATUS_RELEASE_TO_LOAD; 
        } 
    } 
 
    /** 
     * set header status to {@link #HEADER_STATUS_LOADING} 
     */ 
    private void setHeaderStatusLoading() { 
        if (currentHeaderStatus != HEADER_STATUS_LOADING) { 
            resetHeaderPadding(); 
 
            headerImage.setVisibility(View.GONE); 
            headerImage.clearAnimation(); 
            headerProgressBar.setVisibility(View.VISIBLE); 
            headerText.setText(headerLoadingText); 
 
            currentHeaderStatus = HEADER_STATUS_LOADING; 
            setSelection(0); 
        } 
    } 
 
    /** 
     * adjust header padding according to motion event 
     *  
     * @param ev 
     */ 
    private void adjustHeaderPadding(MotionEvent ev) { 
        // adjust header padding according to motion event history 
        int pointerCount = ev.getHistorySize(); 
        if (isVerticalFadingEdgeEnabled()) { 
            setVerticalScrollBarEnabled(false); 
        } 
        for (int i = 0; i < pointerCount; i++) { 
            if (currentHeaderStatus == HEADER_STATUS_DROP_DOWN_TO_LOAD 
                || currentHeaderStatus == HEADER_STATUS_RELEASE_TO_LOAD) { 
                headerLayout.setPadding(headerLayout.getPaddingLeft(), 
                                        (int)(((ev.getHistoricalY(i) - actionDownPointY) - headerOriginalHeight) / headerPaddingTopRate), 
                                        headerLayout.getPaddingRight(), headerLayout.getPaddingBottom()); 
            } 
        } 
    } 
 
    /** 
     * reset header padding 
     */ 
    private void resetHeaderPadding() { 
        headerLayout.setPadding(headerLayout.getPaddingLeft(), headerOriginalTopPadding, 
                                headerLayout.getPaddingRight(), headerLayout.getPaddingBottom()); 
    } 
 
    /** 
     * measure header layout 
     *