Code example for RelativeLayout

Methods: getHeight, getScaleX, getTranslationX, getTranslationY, getWidth, setTranslationY

0
	 * <p>move when zoom in event</p> 
	 * @param view		ScanvasContainer in ImageEditor	 
	 * @param nextScale		next SCanvasContainer scale 
	 */ 
	public void moveToZoomIn(RelativeLayout view, float nextScale) {
		float nextViewWidth = view.getWidth() * nextScale;
		float nextViewHeight = view.getHeight() * nextScale;
		 
		float parentWidth = mSCanvasUtil.getSCanvasParentWidth();
		float parentHeight = mSCanvasUtil.getSCanvasParentHeight();
		 
		float remainWidth = (nextViewWidth - parentWidth) / 2;
		float remainHeight = (nextViewHeight - parentHeight) / 2;
 
		if (remainHeight <= 0) {
			view.setTranslationY(0.0f);
			 
		} else if (nextViewHeight < parentHeight) {
			view.setTranslationY(0);
 
		} else { 
			if (view.getTranslationY() > remainHeight/2) {
				float result = view.getTranslationY() - ((view.getHeight() * view.getScaleX() - nextViewHeight)/2);
				if (result < 0)		result = 0.0f;
				view.setTranslationY(result);
					 
			} else if (view.getTranslationY() < -remainHeight/2) {				
				float result = view.getTranslationY() + ((view.getHeight() * view.getScaleX() - nextViewHeight)/2);
				if (result > 0)		result = 0.0f;
				view.setTranslationY(result);
			} 
		} 
 
 
		if (remainWidth <= 0) {
			view.setTranslationX(0.0f);
			 
		} else if (nextViewWidth < parentWidth) {
			view.setTranslationX(0);
			 
		} else { 
			if (view.getTranslationX() >= remainWidth/2) {
				float result = view.getTranslationX() - ((view.getWidth() * view.getScaleX() - nextViewWidth)/2);
				if (result < 0)		result = 0.0f;
				view.setTranslationX(result);
				 
			} else if (view.getTranslationX() < -remainWidth/2) {
				float result = view.getTranslationX() + ((view.getWidth() * view.getScaleX() - nextViewWidth)/2);
				if (result > 0)		result = 0.0f;
				view.setTranslationX(result);
 
			}  
		}