Ich lade Bild von Server in AsyncTask-Methode. Das Bild wird während des Herunterladens im Vollbildmodus angezeigt, aber nach Abschluss des Downloads wird das Bild in der Mitte des Bildschirms klein. HierBild Größe nach dem Download in Android
ist der Code:
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();
}
}
Geben Sie Ihren XML-Code ein – sJy
Wenn das Bild heruntergeladen wird, haben Sie noch kein Bild, also wie ist es möglich, es im Vollbildmodus anzuzeigen. Sind Sie sicher, dass Sie nicht das gleiche Bild als Hintergrund für die Bildansicht statisch in XML oder Java-Code gesetzt haben. – Tony
Ja das war mein Fehler. Ich hatte es eingestellt. Ich entfernte es und während des Downloads wird nichts angezeigt und wenn der Download abgeschlossen ist, wird das Bild in der Mitte angezeigt und es ist nicht im Vollbildmodus @Tony – moji