志在指尖
用双手敲打未来

android之进度条的实现

packagecom.example.administrator.progress;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.os.Handler;
importandroid.os.Message;
importandroid.widget.ProgressBar;
publicclassMainActivityextendsActivity{
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
finalProgressBarprogressBar=(ProgressBar)findViewById(R.id.progressBar);
finalHandlerhandler=newHandler(){
@Override
publicvoidhandleMessage(Messagemsg){
super.handleMessage(msg);
progressBar.setProgress(msg.what);Android
}
};
finalThreadthread=newThread(){
@Override
publicvoidrun(){
super.run();
intindex=0;
intnumloop=1;
while(index<100){
try{
Thread.sleep(100);
}catch(InterruptedExceptione){
e.printStackTrace();
}
handler.sendEmptyMessage(index);
index++;
if(index==100){
while(index>1){
try{
Thread.sleep(100);
}catch(InterruptedExceptione){
e.printStackTrace();
}
handler.sendEmptyMessage(index);
index–;
}
}
}
}
};
thread.start();
}
}
xmlns:tools=”http://schemas.android.com/tools”
android:id=”@+id/activity_main”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.example.administrator.progress.MainActivity”>
android:id=”@+id/progressBar”
style=”@android:style/Widget.ProgressBar.Horizontal”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”/>

未经允许不得转载:IT技术网站 » android之进度条的实现
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

志在指尖 用双手敲打未来

登录/注册IT技术大全

热门IT技术

C#基础入门   SQL server数据库   系统SEO学习教程   WordPress小技巧   WordPress插件   脚本与源码下载