我在AsyncTask
中设置Progressbar的可见性时遇到问题这是我的代码:
public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView IV;
FullImageActivity MA;
ProgressBar lp1;
public DownloadImageTask(ImageView IV,
FullImageActivity fullImageActivity) {
this.IV = IV;
this.MA = fullImageActivity;
lp1 = (ProgressBar) MA.findViewById(R.id.progressBar1);
}
protected Bitmap doInBackground(String... p) {
String url = "...";
Bitmap BI = null;
try {
InputStream in = new java.net.URL(url).openStream();
BI = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return BI;
}
@Override
protected void onPreExecute() {
lp1.setVisibility(1);
super.onPreExecute();
}
protected void onPostExecute(Bitmap result) {
IV.setImageBitmap(result);
lp1.setVisibility(0);
}
}
和我的XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/full_image_view"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
当我使用
时 lp1.setVisibility(0);
或
lp1.setVisibility(ProgressBar.GONE);
或
lp1.setVisibility(View.GONE);
或
lp1.setVisibility(View.INVISIBLE);
我的progressBar仍然可见