我正在使用AsyncTask從互聯網下載圖像並將其顯示在ImageView中。對於我的應用程序,使用API調用來檢索圖像URL,並使用它在ImageView中顯示。它的工作原理,但圖像真的很小,很難看到。我不知道這是因爲圖像沒有存儲在drawable中,或者如果我在代碼中丟失了某些東西。爲什麼它調整我的形象?在我的應用程序在ImageView中顯示的圖像比源圖像小
圖像的實際大小圖像的
尺寸
RecipePage.java
Results result = new Results();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_recipeviewer, container, false);
new DownloadImageTask((ImageView) rootView.findViewById(R.id.recipe_image))
.execute(result.getURL()); //getURL() just contains the URL of the image
return rootView;
}
class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
個fragment_recipeviewer.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/recipe_image" />
</LinearLayout>
我可能失去了一些東西明顯或做一些愚蠢的。任何解決方案?
你剛纔是不是在建一個使用 –
@PhanVănLinh瞭解Android Studio – Theman
該模擬器我的意思是,哪個模擬器?,samsung s6,nexus 5,或... –