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);
}
}
}
代码笔记 | 宽度与屏幕相等,高度根据图片拉伸后做适配
最新推荐文章于 2024-06-01 20:40:46 发布