【问题标题】:Android progress bar setvisible not workingAndroid进度条设置可见不起作用
【发布时间】:2014-04-06 00:47:39
【问题描述】:

我在 AsyncTask 中设置进度条的可见性时遇到问题

这是我的代码:

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);

我的进度条仍然可见

【问题讨论】:

  • 为什么你使用进度条使用Progress Dialog 并在onPostExecute(.....) 上关闭它
  • tanx @SimplePlan 我用那个

标签: android android-asynctask progress-bar visibility


【解决方案1】:
 lp1.setVisibility(0);

0View.VISIBILE 的值

Here 文档

【讨论】:

    猜你喜欢
    • 2016-01-09
    • 2014-09-05
    • 2018-07-17
    • 1970-01-01
    • 2012-05-01
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    相关资源
    最近更新 更多