progressbar

<?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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值