TextView进度条实现:
private Handler mHandler = new Handler();
private Runnable mRunnable = new getProgressTask();
private class getProgressTask implements Runnable{
public getProgressTask() {
super();
}
@Override
public void run() {
if(progress<100){
mHandler.postDelayed(this, 100);
progress++;
}
mTextView.setText(progress+"%");
if(progress==100){
stopRot();
}
}
}
mButton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progress=0;
mHandler.postDelayed(mRunnable,0);
}
});
ImageView旋转
Animation circle_anim;
private void startRot(){
circle_anim = AnimationUtils.loadAnimation(this, R.anim.anim_round_rotate);
LinearInterpolator interpolator = new LinearInterpolator(); //设置匀速旋转,在xml文件中设置会出现卡顿
circle_anim.setInterpolator(interpolator);
if (circle_anim != null) {
mImageView.startAnimation(circle_anim); //开始动画
}
}
private void stopRot(){
if(mImageView!=null){
mImageView.clearAnimation();
}
}
res下新建anim文件夹anim_round_rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="359"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000"
android:repeatCount="-1" /> <!--设置不断旋转-->
</set>