<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="400.0dip"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ProgressBar
android:id="@+id/bar"
android:background="@drawable/background"
android:layout_width="fill_parent"
android:layout_height="30.0dip"
android:max="100"
android:progress="1"
android:indeterminateOnly="false"
android:progressDrawable="@anim/exp_bar"
style="?android:attr/progressBarStyleHorizontal" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>anim\exp_bar.xml
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@android:id/progress"
android:drawable="@drawable/bar2" />
</layer-list>
package com.example.myprogressbar;
import android.app.Activity;
import android.content.Loader;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ProgressBar;
public class ProgressBarActivity extends Activity
{
private static int barLength;
private ProgressBar bar;
private boolean flag = true;
private Handler myHandler;
public void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
setContentView(R.layout.activity_progress_bar);
ProgressBar localProgressBar = (ProgressBar)findViewById(R.id.bar);
this.bar = localProgressBar;
this.bar.setMax(100);
MyHandler localMyHandler = new MyHandler();
this.myHandler = localMyHandler;
MyThread localMyThread = new MyThread();
new Thread(localMyThread).start();
}
class MyHandler extends Handler
{
public void handleMessage(Message paramMessage)
{
Log.d("MyHandler", "handleMessage......");
super.handleMessage(paramMessage);
String str1 = String.valueOf(paramMessage.arg1);
String str2 = str1;
Log.d("BarLength", str2);
ProgressBar localProgressBar = ProgressBarActivity.this.bar;
int k = paramMessage.arg1;
localProgressBar.setProgress(k);
}
}
class MyThread
implements Runnable
{
MyThread()
{
}
@SuppressWarnings("unused")
public void run()
{
while (true)
{
if (!ProgressBarActivity.this.flag)
return;
long l = 1000L;
try
{
Thread.sleep(l);
label19:
Log.d("thread.......", "mThread........");
Message localMessage = new Message();
if (ProgressBarActivity.barLength <= 100)
ProgressBarActivity.barLength += 5;
else
ProgressBarActivity.barLength = 0;
localMessage.arg1 = ProgressBarActivity.barLength;
ProgressBarActivity.this.myHandler.sendMessage(localMessage);
}
catch (InterruptedException localInterruptedException)
{
localInterruptedException.printStackTrace();
}
}
}
}
}
background.png
bar1.png
bar2.png
progressbar.png