Code example for RelativeLayout

Methods: addViewgetChildAtremoveViewAtrequestLayout, getLayoutParams, getWidth, scrollTo

0
        } 
 
        private void resetHeader(int section) {
            scrollingStart = false;
            addSectionHeader(section);
            mHeader.requestLayout();
            lastResetSection = section;
        } 
 
        private void setMeasurements(int realFirstVisibleItem, int firstVisibleItem) {
 
            if (direction > 0) {
                nextH = realFirstVisibleItem >= firstVisibleItem ? mListView.getChildAt(realFirstVisibleItem - firstVisibleItem).getMeasuredHeight() : 0;
            } 
 
            previous = mHeader.getChildAt(0);
            prevH = previous != null ? previous.getMeasuredHeight() : mHeader.getHeight();
 
            if (direction < 0) {
                if (lastResetSection != actualSection - 1) {
                    addSectionHeader(Math.max(0, actualSection - 1));
                    next = mHeader.getChildAt(0);
                } 
                nextH = mHeader.getChildCount() > 0 ? mHeader.getChildAt(0).getMeasuredHeight() : 0;
                mHeader.scrollTo(0, prevH);
            } 
            doneMeasuring = previous != null && prevH > 0 && nextH > 0;
        } 
 
        private void updateScrollBar() { 
            if (mHeader != null && mListView != null && mScrollView != null) {
                int offset = mListView.computeVerticalScrollOffset();
                int range = mListView.computeVerticalScrollRange();
                int extent = mListView.computeVerticalScrollExtent();
                int top = mListView.getHeight() * offset / range;
                int bottom = mListView.getHeight() - mListView.getHeight() * (offset + extent) / range;
                mScrollView.setPadding(0, top, 0, bottom);
                fadeOut.reset();
                fadeOut.setFillBefore(true);
                fadeOut.setFillAfter(true);
                fadeOut.setStartOffset(FADE_DELAY);
                fadeOut.setDuration(FADE_DURATION);
                mScrollView.clearAnimation();
                mScrollView.startAnimation(fadeOut);
            } 
        } 
 
        private void addSectionHeader(int actualSection) {
            View previousHeader = mHeader.getChildAt(0);
            if (previousHeader != null) {
                mHeader.removeViewAt(0);
            } 
 
            if (mAdapter.hasSectionHeaderView(actualSection)) {
                View header = mAdapter.getSectionHeaderView(actualSection, null, null);
                header.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
 
                header.measure(MeasureSpec.makeMeasureSpec(mHeader.getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
 
                mHeader.getLayoutParams().height = header.getMeasuredHeight();
                header.scrollTo(0, 0);
                mHeader.scrollTo(0, 0);
                mHeader.addView(header, 0);
            } else { 
                mHeader.getLayoutParams().height = 0;
                mHeader.scrollTo(0, 0);
            } 
 
            mScrollView.bringToFront();
        }