0
私はAsyncTaskメソッドでサーバーからイメージをダウンロードしています。それはダウンロード中にフルスクリーンで画像を表示しますが、ダウンロードが完了すると画面の中央で画像が小さくなります。ここでイメージはAndroidでダウンロードした後にリサイズされます
はコードです:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.show_pics);
DownloadTask downloadTask = new DownloadTask();
downloadTask.execute("https://cms-assets.tutsplus.com/uploads/users/21/posts/19431/featured_image/CodeFeature.jpg");
}
private Bitmap downloadUrl(String strUrl) throws IOException {
Bitmap bitmap = null;
InputStream iStream = null;
try {
URL url = new URL(strUrl);
/** Creating an http connection to communcate with url */
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
/** Connecting to url */
urlConnection.connect();
/** Reading data from url */
iStream = urlConnection.getInputStream();
/** Creating a bitmap from the stream returned from the url */
bitmap = BitmapFactory.decodeStream(iStream);
} catch (Exception e) {
//Log.d("Exception while downloading url", e.toString());
} finally {
iStream.close();
}
return bitmap;
}
private class DownloadTask extends AsyncTask<String, Integer, Bitmap> {
Bitmap bitmap = null;
@Override
protected Bitmap doInBackground(String... url) {
try {
bitmap = downloadUrl(url[0]);
} catch (Exception e) {
//Log.d("Background Task",e.toString());
}
return bitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
/** Getting a reference to ImageView to display the
* downloaded image
*/
ImageView iView = (ImageView) findViewById(R.id.TahlilImageView);
/** Displaying the downloaded image */
iView.setImageBitmap(result);
/** Showing a message, on completion of download process */
Toast.makeText(getBaseContext(), "Image downloaded successfully", Toast.LENGTH_SHORT).show();
}
}
あなたのXMLコードを投稿 – sJy
画像がダウンロードされているときにまだ画像がありません。どのようにフルスクリーンで表示することができますか?あなたは、XMLやJavaコードで静的にimageviewの背景と同じ画像を設定していないのですか? – Tony
はい、それは私の間違いでした。私はそれを設定していた。私はそれを削除し、ダウンロード中は何も表示されず、ダウンロードが完了すると画像は中央に表示され、フルスクリーンでは表示されません@トニー – moji