我有一个异步任务,该任务将一定数量的图像url作为输入,下载图像后将其放入imageViews中,并返回包含imageView和进度条的相对布局(在下载图像时显示)。所以我想做的就是将包含imageView和progressBar的相对布局作为一行放入listView中。这可能吗?
ImageDownloader类:
apply plugin: 'com.android.library'
apply plugin: 'checkstyle'
// make sure this line comes *after* you apply the Android plugin
apply plugin: 'com.getkeepsafe.dexcount'
assemble.dependsOn('lint')
check.dependsOn('checkstyle')
ImageUI类:
class ImageDownloader extends AsyncTask<String, Void, Bitmap> {
private ImageView imageView;
private ProgressBar progressBar;
public ImageDownloader(ImageView imageView, ProgressBar progressBar/*, ImageDownloader imageDownloader*/) {
this.imageView = imageView;
this.progressBar = progressBar;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
imageView.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
}
@Override
protected Bitmap doInBackground(String... params) {
try {
URL url = new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
System.out.println("Content Type = " + connection.getContentType());
if (connection.getContentType().contains("image")) {
InputStream inputStream = connection.getInputStream();
return BitmapFactory.decodeStream(inputStream);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
try {
System.out.println("Bitmaaap = "+bitmap);
imageView.setImageBitmap(bitmap);
progressBar.setVisibility(View.GONE);
imageView.setVisibility(View.VISIBLE);
} catch (Exception e) {
e.printStackTrace();
}
}
}