xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/progress">
<clip
android:clipOrientation="vertical"
android:drawable="@drawable/security_scaned_safe"
android:gravity="bottom" />
</item>
</layer-list>
package com.example.myprogresstest;
import com.example.myprogressbar.MyProgressBar;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends Activity {
private Handler handler;
private Runnable runnable;
private ProgressBar progressBar1;
private MyProgressBar progressBar2;
private int value;
ImageView mImage;
boolean isRotate = true;
Animation operatingAnim;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);
progressBar2 = (MyProgressBar)findViewById(R.id.progressBar2);
mImage = (ImageView)findViewById(R.id.icon);
operatingAnim = AnimationUtils.loadAnimation(this, R.anim.hb_fragment_music_animation);
LinearInterpolator lin = new LinearInterpolator();
operatingAnim.setInterpolator(lin);
mImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (operatingAnim != null) {
if(isRotate){
v.startAnimation(operatingAnim);
isRotate = false;
}else{
v.clearAnimation();
isRotate = true;
}
}
}
});
HandlerInit();
handler.post(runnable);
}
private void HandlerInit() {
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
progressBar1.setProgress((int) (25+value*0.68));
progressBar2.setProgress(value);
value += 2;
if (value >= 100) {
value = 0;
}
handler.postDelayed(runnable, 500);
}
};
}
}
demo:http://download.csdn.net/detail/zhongwn/9464216