2011-09-16 74 views
6

我有一个应该在的AsyncTask运行进度,但它没有出现,虽然任务运行Android的进度条不显示

XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" android:layout_height="match_parent" 
android:background="@drawable/splashportrait"> 
<ProgressBar android:layout_alignParentBottom="true" android:indeterminate="true" 
    android:layout_centerHorizontal="true" android:paddingBottom="450dip" 
    android:layout_width="200dip" android:layout_height="200dip" 
    android:id="@+id/progressBar1"></ProgressBar> 
</RelativeLayout> 

CODE:

ProgressBar diagProgress; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splashscreen); 

    diagProgress = (ProgressBar)findViewById(R.id.progressBar1); 
    DiagnosticsTask diag = new DiagnosticsTask(); 
    diag.execute(); 

    /**rest of class ommitted here**/ 
} 

private class DiagnosticsTask extends AsyncTask<String, String, Boolean> { 

    //Show spinner 
    protected void onPreExecute() { 
     //dialog.setMessage("Loading corresponding destinations..."); 
     //dialog.show(); 
     diagProgress.setVisibility(View.VISIBLE); 
     diagProgress.showContextMenu(); 
     Log.e("AsyncStatus", "spinner shown"); 
    } 
/*other parts of the thread ommitted here*/ 

} 
+0

嘿你问题解决了吗? – shyam

回答

14

试试用下面的代码替换ProgressBar。

<ProgressBar android:indeterminate="true" 
android:layout_centerInParent="true" 
android:layout_width="wrap_content" android:layout_height="wrap_content" 
android:id="@+id/progressBar1"></ProgressBar> 

让我知道它是否有效,我会解释原因。

理由: 现在我把下面的代码进度

<ProgressBar android:layout_alignParentBottom="true" android:indeterminate="true" 
android:layout_centerHorizontal="true" android:paddingBottom="450dip" 
android:layout_width="200dip" android:layout_height="200dip" 
android:id="@+id/progressBar1"></ProgressBar> 

的RelativeLayout允许您Z排序。所以,由于您需要ProgressBar,所以您无需执行您正在进行的操作。

android:layout_alignParentBottom="true" 

这将进度条的布局的钮:

android:paddingBottom="450dip" android:layout_width="200dip" android:layout_height="200dip" 

这三个位置值是绝对是一个严格的禁忌至于Android的关注。最有可能你的paddingBottom将你的ProgressBar推出View。由于您的填充大于控件的实际宽度/高度,因此您需要使用相对值来处理所有设备和窗体因素。

让我知道这是否合理。

+2

这个工作原理?它似乎无法在白色背景上看到,谢谢 – CQM

+0

检查的理由,让我知道如果你需要一些更多的信息。 – PravinCG

+1

感谢CQM为白色背景评论(脸掌) – saswanb

0

你忘了执行你的任务吗?

... 
    diagProgress = (ProgressBar)findViewById(R.id.progressBar1); 
    new DiagnosticsTask().execute(); 


    .... 
+0

任务运行时,我提到过,我会编辑我的代码片段以显示该部分 – CQM

7

我有这个问题,当我忘记打开动画后测试xD

+0

这可能是一个很好的答案,但一个解释会有所帮助。 – Bobby

+1

我得到了同样的问题。当你在android上进行UI测试时,你必须禁用动画,所以出现奇怪的UI行为(如进度条根本不显示)!这不是一个错误的答案,因为它会让我走向正确的方向:) – Spoke44

+0

同样发生在我身上。检查您的Android设备:设置>开发>任何关于动画 – OneWorld