我的应用中有导航抽屉。我正在发送HTTP请求以加载朋友和组名以及图片。我希望我的照片调整大小以便他们可以调整。这就是我所拥有的
这就是我想要的
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
int k=0;
for(String n : friends){
String words[] = n.split(":");
menu.findItem(R.id.friends).getSubMenu().add(R.id.friends, Integer.parseInt(words[1]),k,words[0]);
MenuItem myMenuItem = menu.findItem(R.id.friends).getSubMenu().findItem(Integer.parseInt(words[1]));
DownloadImageTask dn = new DownloadImageTask(myMenuItem);
dn.execute(AppConfig.IMAGESURL + words[2]);
}
}
public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
private final WeakReference<MenuItem> menuItemReference;
public DownloadImageTask(MenuItem menuItem) {
menuItemReference = new WeakReference<>(menuItem);
}
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 bitmap) {
if (isCancelled()) {
bitmap = null;
}
if (menuItemReference != null) {
MenuItem menuitem = menuItemReference.get();
if (menuitem != null) {
if (bitmap != null) {
Drawable r = new BitmapDrawable(getResources(),bitmap);
menuitem.setIcon(r);
} else {
// Drawable placeholder = imageView.getContext().getResources().getDrawable(R.drawable.placeholder);
// imageView.setImageDrawable(placeholder);
}
}
}
}
}