1
ImageView
を、リモートサーバーからダウンロードしてデバイスのローカルストレージに保存したファイルに設定します。何らかの理由で、画像が歪んでいます。私の研究でscaleType
、adjustViewBounds
、maxWidth
、maxHeight
というプロパティをImageView
に設定すると、アンドロイドは画像をスケールします。 Android以外のAndroid開発では、画像を表示する前に必ずプログラムのサイズを変更する必要があったため、奇妙に思えます。しかし、this postはAndroidがそれを行うと言います。Progammatically ImageViewによる歪みの設定
これは私が表示しようとしているイメージです。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);
}