Android进度条设置无法正常工作

时间:2014-03-04 13:02:31

标签: android android-asynctask progress-bar visibility

我在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仍然可见

1 个答案:

答案 0 :(得分:0)

 lp1.setVisibility(0);

0View.VISIBILE

的值

Here文档