1
我想加載多個ImageView與畢加索,但它只加載一個ImageView。這是我的代碼:從畢加索的URL加載多個Imageview?
public void setClassicImg(JSONArray listImg, RelativeLayout rl) throws JSONException, IOException, MalformedURLException {
if (listImg.length() > 0)
{
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
for (int i = 0; i < listImg.length(); i++)
{
ImageView downloadedImg = new ImageView(this);
// downloadedImg.setBackgroundColor(Color.parseColor(listImg.getJSONObject(i).getString("color")));
// new DownloadImageTask(downloadedImg).execute(listImg.getJSONObject(i).getString("http"));
Picasso.with(this.getApplicationContext()).load(listImg.getJSONObject(i).getString("http")).into(downloadedImg);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) (metrics.widthPixels * listImg.getJSONObject(i).getDouble("size_x")), (int) (metrics.heightPixels * listImg.getJSONObject(i).getDouble("size_y")));
params.leftMargin = (int) (metrics.widthPixels * listImg.getJSONObject(i).getDouble("position_x"));
params.topMargin = (int) (metrics.heightPixels * listImg.getJSONObject(i).getDouble("position_y"));
downloadedImg.setScaleType(ImageView.ScaleType.FIT_XY);
// downloadedImg.getLayoutParams().width = BIND_ALLOW_OOM_MANAGEMENT;
/// downloadedImg.setBackgroundDrawable(animation);
// downloadedImg.setImageDrawable(animation);
rl.addView(downloadedImg, params);
}
}
}
我解析一個json文件。包含Image的.png或.jpg的字符串位於字符串http中,因此我可以得到它,但是在設備上,它只顯示加載的第一個ImageView,好像它是一次循環一樣。
有人對我做錯了什麼想法嗎?
我有同樣的問題,它的任何更新? –