Android 进度条不显示
我有一个应该在 AsyncTask 中运行的进度条,但它没有出现,尽管任务运行
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*/
}
I have a progressbar that is supposed to run in an AsyncTask , but it is not appearing, although the task runs
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*/
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当我在测试后忘记打开动画时遇到了这个问题 xD
I had that issue when I forgot to turn on animations after testing xD
尝试用下面的替换您的 ProgressBar。
让我知道它是否有效,我会解释原理。
理由:
现在我将您的代码放在下面,ProgressBarrelativeLayout
允许您进行 Z 排序。因此,由于您需要在顶部添加 ProgressBar,因此您无需执行您正在执行的操作。
这会将进度条设置在布局的底部:
这里的所有三个值都是绝对值,这对于 Android 而言是严格禁止的。最有可能的是你的 paddingBottom 将你的 ProgressBar 推出了视图。由于您的填充大于控件的实际宽度/高度,
因此经验法则始终使用相对值,使其适用于所有设备和外形尺寸。
让我知道这是否有意义。
Try this replace your ProgressBar with the one below.
Let me know if it works, I would explain the rationale.
Rationale:
Now I am putting your code below for ProgressBar
RelativeLayout allows you Z-ordering. So since you needed ProgressBar on top you need not do the kind of manipulations you are doing.
This sets the Progress Bar at the botton of the layout:
All the three values here are absolute which is a strict no-no as far as Android is concerned. Most Likely your paddingBottom was pushing your ProgressBar out of View. As your padding is greater than the actual width/height of the control
As a thumb rule always use relative values for it to work on all the devices and form factors.
Let me know if this makes sense.
您忘记执行任务了吗?
Did you forget to execute your task?
当我使可见性消失和可见瞬间消失使隐形在我的情况下工作不可见和可见时,我遇到了这个问题
I had that issue when I make visibility gone and visible instant of gone make invisible in my case working invisible and visible
我有这个问题。我通过进入 theme.xml 并撤消对主要品牌颜色所做的更改来解决这个问题。
当我将其改回这些颜色时,出现进度条:
I had this issue. I solved it by going into themes.xml and undoing the changes I made to the primary brand colors.
The progress bar appeared when I changed it back to these colors: