Code example for RelativeLayout

Methods: getHeight, getLayoutParams, setLayoutParams

0
	} 
 
	private void setHeaderPadding(int padding){
		headerPadding = padding;
 
		MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) header.getLayoutParams();
		mlp.setMargins(0, Math.round(padding), 0, 0);
		header.setLayoutParams(mlp);
	} 
	 
	private boolean isPulling = false;
	private boolean isPull(MotionEvent event){
		return isPulling;
	} 
	 
	@Override 
	public boolean onInterceptTouchEvent(MotionEvent event) {
		if(lockScrollWhileRefreshing
				&& (state == State.REFRESHING || getAnimation() != null && !getAnimation().hasEnded())){
			return true;	//consume touch event here.. 
		} 
		 
		switch(event.getAction()){
		case MotionEvent.ACTION_DOWN:
			if( getFirstVisiblePosition() == 0 ) 
				previousY = event.getY();
			break; 
		case MotionEvent.ACTION_MOVE:
			if( getFirstVisiblePosition() == 0 && event.getY() - previousY > 0 ) {
				isPulling = true;
				return true; 
			}else{ 
				isPulling = false;
			} 
			break; 
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
			isPulling = false;
			break; 
		} 
		 
		return super.onInterceptTouchEvent(event);
	} 
 
	@Override 
	public boolean onTouchEvent(MotionEvent event){
		if(lockScrollWhileRefreshing
				&& (state == State.REFRESHING || getAnimation() != null && !getAnimation().hasEnded())){
			return true; 
		} 
 
		switch(event.getAction()){
 
		case MotionEvent.ACTION_UP:
			if(isPull(event) && (state == State.RELEASE_TO_REFRESH || getFirstVisiblePosition() == 0)){
				switch(state){
				case RELEASE_TO_REFRESH:
					setState(State.REFRESHING);
					bounceBackHeader(); 
					break; 
				case PULL_TO_REFRESH:
					resetHeader(); 
					break; 
				default: 
					break; 
				} 
			} 
			break; 
 
		case MotionEvent.ACTION_MOVE:
			if(isPull(event)){
				float y = event.getY();
				float diff = y - previousY;
				if(diff > 0) diff /= PULL_RESISTANCE;
				previousY = y;
 
				int newHeaderPadding = Math.max(Math.round(headerPadding + diff), -header.getHeight());
 
				if(newHeaderPadding != headerPadding && state != State.REFRESHING){
					setHeaderPadding(newHeaderPadding);
 
					if(state == State.PULL_TO_REFRESH && headerPadding > 0){