您的位置:首页 > 其它

自定义imageview使图片高度和宽度相等

2014-12-13 15:48 127 查看
public class ResizableImageView extends ImageView {

public ResizableImageView(Context context) {

super(context);

}

public ResizableImageView(Context context, AttributeSet attrs) {

super(context, attrs);

}

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

Drawable d = getDrawable();

if (d != null) {

// ceil not round - avoid thin vertical gaps along the left/right edges

int width = MeasureSpec.getSize(widthMeasureSpec);

int height = (int) Math.ceil((float) width * (float) d.getIntrinsicHeight() / (float) d.getIntrinsicWidth());

setMeasuredDimension(width, height);

} else {

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐