Code example for ViewTreeObserver

Methods: addOnGlobalLayoutListener

2
		mButtons = buttons;
		mVgMain = mainVG;
		mActivity = activity;
		 
		ViewTreeObserver vto = mMainButton.getViewTreeObserver();
		vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener(){
			@Override 
			public void onGlobalLayout() { 
				initalizeAnmition(); 
				ViewTreeObserver obs = mVgMain.getViewTreeObserver();
				obs.removeGlobalOnLayoutListener(this);
			}}); 
	} 
	 
	public void initalizeAnmition() { 
		Util.LogMsg(TAG, "initalizeAnmition"); 
		/* Initialize basic values */ 
		/* & set main Button LayoutParam */ 
		double nDistance; 
		nDistance = mVgMain.getWidth() / 2 * 0.732 / 2 + mMainButton.getWidth();