我正在使用自定义标题视图,并希望在线程工作时在标题视图中显示/隐藏进度条。Android - 使用runOnUiThread从线程执行UI更改
这是我的标题视图的XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/image_left_btn"
android:layout_width="75dip"
android:layout_height="wrap_content"
android:text="Back"
/>
<TextView
android:id="@+id/image_title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20dip"
android:textStyle="bold"
android:textColor="#fff"
android:layout_gravity="center"
android:gravity="center"
android:paddingLeft="8dip"
android:paddingRight="8dip"
/>
<ProgressBar
android:id="@+android:id/progress_small_title"
style="?android:attr/progressBarStyleSmall"
android:layout_width="75dip"
android:layout_height="wrap_content"
android:paddingRight="8dip"/>
</LinearLayout>
在我的活动,设置此为自定义标题栏后,我做这个
titleProgress = (ProgressBar)findViewById(R.id.progress_small_title);
titleProgress.setVisibility(View.INVISIBLE);
其中titleProgress是进度的对象。
这是我在我的线程
runOnUiThread(new Runnable() {
public void run() {
titleProgress.setVisibility(View.VISIBLE);
}
});
//long operation here
runOnUiThread(new Runnable() {
public void run() {
titleProgress.setVisibility(View.INVISIBLE);
}
});
做但有进度条没有变化。它从不显示。有人可以告诉我什么是错误的代码?
是否可以在自定义标题中显示标题进度条?
谢谢。
已经尝试了前两个,但没有帮助!而绝望,我是这样想的,要求3? ;) – lostInTransit 2009-09-23 08:01:21
3)选项是解决所有问题的最佳解决方案...... LOL – Rodrigo 2016-04-22 20:41:05