<?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"> <!-- 长方形进度条,一开始不可见,直到点击按钮时才出现进度条 --> <ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyleHorizontal" mce_style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:visibility="gone" android:max="100" /> <!-- 圆形进度条 --> <!--<ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyleLarge" mce_style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" />--> <Button android:id="@+id/start" android:text="启动进度条" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/stop" android:text="停止进度条" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
package com.ljq.pb;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class PbActivity extends Activity {
private ProgressBar progressBar = null;
private Button start = null, stop = null;
// 定义Handler对象
private Handler handler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setProgress(0);
start = (Button) findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
handler.post(runnable); //开始执行
}
});
stop=(Button)findViewById(R.id.stop);
stop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
handler.removeCallbacks(runnable);//停止执行
progressBar.setProgress(0);
}
});
}
int pro=0;
Runnable runnable=new Runnable(){
public void run() {
progressBar.setVisibility(View.VISIBLE);
pro=progressBar.getProgress()+10;
progressBar.setProgress(pro);
//如果进度小于100,,则延迟1000毫秒后重复执行runnable
if(pro<100){
handler.postDelayed(runnable, 1000);
}else{
progressBar.setVisibility(View.GONE);
startActivity(new Intent(PbActivity.this, TestActivity.class));
handler.removeCallbacks(runnable);
progressBar.setProgress(0);
}
}
};
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有