public class ScaleScreenImageView extends ImageView {
public ScaleScreenImageView(Context context) {
super(context);
}
public ScaleScreenImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScaleScreenImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void setImageBitmap(Bitmap bm) {
super.setImageBitmap(bm);
if (getWidth() > 0) {
float es = (float) getWidth() / (float)bm.getWidth();
int height = (int) (bm.getHeight() * es);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = height;
setLayoutParams(params);
}
}
}
05-11
6593