public void measure(int widthMeasureSpec, int heightMeasureSpec, double aspectRatio) {
			int widthMode = MeasureSpec.getMode( widthMeasureSpec );
			int widthSize = widthMode == MeasureSpec.UNSPECIFIED ? Integer.MAX_VALUE : MeasureSpec.getSize( widthMeasureSpec );
			int heightMode = MeasureSpec.getMode( heightMeasureSpec );
			int heightSize = heightMode == MeasureSpec.UNSPECIFIED ? Integer.MAX_VALUE : MeasureSpec.getSize( heightMeasureSpec );

			if ( heightMode == MeasureSpec.EXACTLY && widthMode == MeasureSpec.EXACTLY ) {
				/* 
				 * Possibility 1: Both width and height fixed
				 */
				measuredWidth = widthSize;
				measuredHeight = heightSize;

			} else if ( heightMode == MeasureSpec.EXACTLY ) {
				/*
				 * Possibility 2: Width dynamic, height fixed
				 */
				measuredWidth = (int) Math.min( widthSize, heightSize * aspectRatio );
				measuredHeight = (int) (measuredWidth / aspectRatio);

			} else if ( widthMode == MeasureSpec.EXACTLY ) {
				/*
				 * Possibility 3: Width fixed, height dynamic
				 */
				measuredHeight = (int) Math.min( heightSize, widthSize / aspectRatio );
				measuredWidth = (int) (measuredHeight * aspectRatio);

			} else {
				/* 
				 * Possibility 4: Both width and height dynamic
				 */
				if ( widthSize > heightSize * aspectRatio ) {
					measuredHeight = heightSize;
					measuredWidth = (int)( measuredHeight * aspectRatio );
				} else {
					measuredWidth = widthSize;
					measuredHeight = (int) (measuredWidth / aspectRatio);
				}

			}
		}
Measure with a specific aspect ratio<br />
<br />
After measuring, get the width and height with the {@link #getMeasuredWidth()}
and {@link #getMeasuredHeight()} methods, respectively.
@param widthMeasureSpec The width <tt>MeasureSpec</tt> passed in your <tt>View.onMeasure()</tt> method
@param heightMeasureSpec The height <tt>MeasureSpec</tt> passed in your <tt>View.onMeasure()</tt> method
@param aspectRatio The aspect ratio to calculate measurements in respect to
src/net/majorkernelpanic/streaming/gl/SurfaceView.java