【发布时间】:2013-07-22 18:24:47
【问题描述】:
我有一个 80dp * 80dp 的位图。 ImageView 大小会自动缩放。
ImageView 大小为:130DP * 130DP(大于位图大小)。
我试图让位图适合 imageView 大小(我不介意丢失图像质量)。
这里有一些代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.inturnex.safecam.SquareImageView
android:id="@+id/imageView"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:src="@drawable/locked_image"
android:adjustViewBounds="true"
android:scaleType="fitXY"
/>
</LinearLayout>
我正在以编程方式设置位图。 ImageView 大小为 130DP,但我看到的图像大小为 80DP(作为原始位图,它不会拉伸以适应 ImageView 大小)。
我可以做些什么来完成这项任务?谢谢!
编辑: SquareImageView 实现:
public class SquareImageView extends ImageView {
public SquareImageView(Context context) {
super(context);
}
public SquareImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); //Snap to width
}
}
【问题讨论】:
-
@Stacks28 看代码,有FitXY的使用。哦,我没有以编程方式尝试。
-
以编程方式使用 imageview.setScaleType(ScaleType.FIT_XY);
-
@Stacks28 还是一样的结果。
-
com.inturnex.safecam.SquareImageView 是一个什么样的对象?在转向自定义对象之前,我会尝试使用普通的旧 imageView...
-
@Stacks28 你能提供一个图像缩略图的例子吗?它对我有什么帮助?我正在寻找最佳的内存解决方案。
标签: java android bitmap imageview scale