android之通过clip自定义progress进度条样式

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值