【发布时间】:2018-03-04 07:56:09
【问题描述】:
我正在将ImageView 设置为从远程服务器下载的文件,然后保存到设备的本地存储中。由于某种原因,图像变得扭曲。根据我的研究,如果我设置了ImageView 的scaleType、adjustViewBounds、maxWidth 和maxHeight 属性,那么Android 将为我缩放图像。这看起来很奇怪,因为在我的其他非 Android 开发中,我总是必须先以编程方式调整图像大小,然后再显示它。但是,this post 表示 Android 会这样做。
这是我要显示的图像:Image
扭曲的图像:
代码:
<ImageView
android:id="@+id/title_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="60dp"
android:maxHeight="60dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
/>
String path = getExternalStorageDirectory() + "/MyApp/Images";
String fileName = "Test.jpg";
File imageFile = new File(path, fileName);
if (imageFile.exists())
{
Uri imageUri = Uri.fromFile(imageFile);
((ImageView)findViewById(R.id.title_image)).setImageURI(thumbnail);
}
【问题讨论】:
标签: android android-imageview image-scaling