【发布时间】:2017-12-17 19:01:24
【问题描述】:
我想知道封面图像裁剪的确切大小。我的应用程序的 UI 设计如下所示。我如何裁剪图像以完全适合所有版本的 android 手机。 如果我采用位图图像的确切长度和宽度。后台线程需要花费大量时间来加载图像。
下面给出了我的图像裁剪代码,但这仅适用于图像大小,因为边缘有很多空白空间。
public class ProportionalImageView extends AppCompatImageView {
public ProportionalImageView(Context context) {
super(context);
}
public ProportionalImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProportionalImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Drawable d = getDrawable();
if (d != null) {
int w = MeasureSpec.getSize(widthMeasureSpec);
int h = w * d.getIntrinsicHeight() / d.getIntrinsicWidth();
setMeasuredDimension(w, h);
}
else super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
提前致谢
【问题讨论】:
-
可以将ImageView的“android:scaleType”属性设置为“centerCrop”。
-
@NavinGupta 没有变化,现在也有空间了。
-
如果你的图像尺寸比你的视图小,那么你的视图就会留下空间。所以你必须根据你的 ImagView 的尺寸来缩放你的位图。或者使用“scaleType”=“fitXY”。但在这种情况下,图像将被破坏
标签: android image image-processing