package com.wasu.cs.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

public class ImageViewFit extends ImageView {
	/** 用于计算宽高比 **/
	private int imageWidth 	= 476;
	private int imageHeight = 265;
	public ImageViewFit(Context context) {
	    super(context);
	}

	public ImageViewFit(Context context, AttributeSet attrs) {
	    super(context, attrs);
	}

	public ImageViewFit(Context context, AttributeSet attrs, int defStyle) {
	    super(context, attrs, defStyle);
	}

	public void setImageRealSize(int width, int height){
		imageWidth = width;
		imageHeight= height;
	}
	
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
	    int width = MeasureSpec.getSize(widthMeasureSpec);
	    int height = width * imageHeight / imageWidth;
	    setMeasuredDimension(width, height);
	}
}
