Back to project page downtown.
The source code is released under:
GNU General Public License
If you think the Android project downtown listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.dklisiaris.downtown.widgets; //from ww w . ja v a2 s . c o m import android.content.Context; import android.util.AttributeSet; import android.widget.ImageView; public class AspectRatioImageView extends ImageView { public AspectRatioImageView(Context context) { super(context); } public AspectRatioImageView(Context context, AttributeSet attrs) { super(context, attrs); } public AspectRatioImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = 0; try { if(getDrawable()!=null) { height = width * getDrawable().getIntrinsicHeight() / getDrawable().getIntrinsicWidth(); } }catch(ArithmeticException e){} setMeasuredDimension(width, height); } }