您的位置:首页 > 其它

ImportError: No module named items

2015-04-29 16:07 295 查看
ProgressBar进度条的使用:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello" />
<ProgressBar android:id="@+id/ProgressBar01"
style="?android:attr/progressBarStyleHorizontal" android:visibility="gone"
android:layout_width="fill_parent" android:layout_height="wrap_content"></ProgressBar>
<ProgressBar android:id="@+id/ProgressBar02"
android:visibility="gone" android:max="100" android:progress="50"
android:secondaryProgress="70" style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content" android:layout_height="wrap_content"></ProgressBar>
<Button android:id="@+id/Button" android:text="start"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>


package com.Aina.Android;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;

public class Test_ProgressBar extends Activity {
/** Called when the activity is first created. */
private ProgressBar pBar1, pBar2;
private Button btn;
protected static final int STOP = 0x108;
protected static final int NEXT = 0x109;
private int iCount = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_PROGRESS);// 设置窗口属性
this.setProgressBarVisibility(true);// 显示
setContentView(R.layout.main);
pBar1 = (ProgressBar) this.findViewById(R.id.ProgressBar01);
pBar2 = (ProgressBar) this.findViewById(R.id.ProgressBar02);
btn = (Button) this.findViewById(R.id.Button);
pBar1.setIndeterminate(false);
pBar2.setIndeterminate(false);
btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pBar1.setVisibility(View.VISIBLE);
pBar2.setVisibility(View.VISIBLE);// 设置为可见
pBar1.setMax(100);// 设置最大值
pBar1.setProgress(0);
pBar2.setProgress(0);// 设置当前值
new Thread(new Runnable(){

@Override
public void run() {
// TODO Auto-generated method stub
for(int i=0;i<10;i++){
try{
iCount = (i+1)*20;
Thread.sleep(1000);
if(i==4){
Message msg = new Message();
msg.what = STOP;
Test_ProgressBar.this.mHandler.sendMessage(msg);
break;
}else{
Message msg= new Message();
msg.what = NEXT;
Test_ProgressBar.this.mHandler.sendMessage(msg);
}
}catch(Exception ex){
ex.printStackTrace();
}
}
}

}){

}.start();
}

});
}

private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch(msg.what){
case STOP://到了最大值
pBar1.setVisibility(View.GONE);
pBar2.setVisibility(View.GONE);//设置进度条不可见
Thread.currentThread().interrupt();//中断当前线程.
break;
case NEXT:
if(!Thread.currentThread().isInterrupted()){//当前线程正在运行
pBar1.setProgress(iCount);
pBar2.setProgress(iCount);//设置当前值
Test_ProgressBar.this.setProgress(iCount*100);
Test_ProgressBar.this.setSecondaryProgress(iCount*100);
}
break;
}
super.handleMessage(msg);
}
};
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: