Android之自定义ProgressBar

本文简单介绍下Android之自定义ProgressBar。

多的不说,先上图

Android之自定义ProgressBar_第1张图片 Android之自定义ProgressBar_第2张图片


布局文件

activity_main.xml



    
    
    
    
    
    
    
    
        

布局文件关联的文件

progress_horizontal.xml




    
    
    
    
        
    
    
    
        
    


progressbar_layer_list.xml




	
	

	
	


progress_selector.xml



	
		
	

主程序

package com.sl.progressbardemo;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar;
import android.app.Activity;

public class MainActivity extends Activity
{
	private ProgressBar mProgressBar2;
	private ProgressBar mProgressBar3;
	private ProgressBar mProgressBar4;
	private Button mButton1;
	private Button mButton2;
	private Button mButton3;
	private Button mButton4;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_PROGRESS);
		setContentView(R.layout.activity_main);
		setProgressBarVisibility(true);
		
		mProgressBar2 = (ProgressBar)findViewById(R.id.progress2);
		mProgressBar3 = (ProgressBar)findViewById(R.id.progress3);
		mProgressBar4 = (ProgressBar)findViewById(R.id.progress4);
		mButton1 = (Button)findViewById(R.id.btn1);
		mButton2 = (Button)findViewById(R.id.btn2);
		mButton3 = (Button)findViewById(R.id.btn3);
		mButton4 = (Button)findViewById(R.id.btn4);
		mButton1.setOnClickListener(listener);
		mButton2.setOnClickListener(listener);
		mButton3.setOnClickListener(listener);
		mButton4.setOnClickListener(listener);
		
	}
	
	Button.OnClickListener listener = new OnClickListener()
	{
		@Override
		public void onClick(View v)
		{
			Button button = (Button)v;
			switch (button.getId())
			{
			case R.id.btn1:
				mProgressBar2.incrementProgressBy(-5);
				mProgressBar3.incrementProgressBy(-5);
				mProgressBar4.incrementProgressBy(-5);
				break;
			case R.id.btn2:
				mProgressBar2.incrementProgressBy(5);
				mProgressBar3.incrementProgressBy(5);
				mProgressBar4.incrementProgressBy(5);
				break;
			case R.id.btn3:
				mProgressBar2.incrementSecondaryProgressBy(-5);
				mProgressBar3.incrementSecondaryProgressBy(-5);
				break;
			case R.id.btn4:
				mProgressBar2.incrementSecondaryProgressBy(5);
				mProgressBar3.incrementSecondaryProgressBy(5);
				break;
			default:
				break;
			}
		}
	};
}

源码下载


你可能感兴趣的:(Android开发,Android,自定义,ProgressBar)