Back to project page kluster-android.
The source code is released under:
Apache License
If you think the Android project kluster-android 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 android.app; //from ww w. ja v a 2 s.c o m import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.widget.ImageView; /** * ImageView that keeps aspect ratio when scaled */ public class ScaleImageView extends ImageView { public ScaleImageView(Context context) { super(context); } public ScaleImageView(Context context, AttributeSet attrs) { super(context, attrs); } public ScaleImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Drawable drawable = getDrawable(); if (drawable != null) { int width = MeasureSpec.getSize(widthMeasureSpec); int diw = drawable.getIntrinsicWidth(); if (diw > 0) { int height = width * drawable.getIntrinsicHeight() / diw; setMeasuredDimension(width, height); } else super.onMeasure(widthMeasureSpec, heightMeasureSpec); } else super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }