先上图:
我们得自己定义ProgressBar的样式
- //定义的是背景色
- //假设有2级进度,须要定义这一项,gradient定义的是渐变色,clip假设没有的话,进度条会充满整个Progessbar
- //这个是定义1级进度,假设1级进度比2级进度大且1级进度不透明。就能够覆盖掉2级进度
在代码里这样使用:
private ProgressBar mProgressBar; private Task mTask = new Task(); private int mCount = 0; private Handler mHander = new MyHandler(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); mProgressBar = (ProgressBar)findViewById(R.id.progress); Timer timer = new Timer(); timer.schedule(mTask, 1000, 1000); } private class MyHandler extends Handler{ @Override public void handleMessage(Message msg) { mCount += 10; mProgressBar.setProgress(mCount); super.handleMessage(msg); } } private class Task extends TimerTask{ @Override public void run() { mHander.sendEmptyMessage(10); } }对于圆形并有转圈动画的进度条:shape的值(rectagle矩形,oval椭圆,line水平直线。ring环形) tpye的值:渐变的样式 liner线性渐变 radial环形渐变 sweep
xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0" android:toDegrees="360"> <shape android:shape="ring"<span style="font-family:verdana, ms song, 宋体, Arial, 微软雅黑, Helvetica, sans-serif;color:#666666;"><span style="font-size: 14px; line-height: 18px;"> </span></span> android:innerRadiusRatio="3" android:thicknessRatio="8" android:useLevel="false"> <size android:width="37dip" android:height="37dip" /> <gradient android:type="sweep"//type为sweep为环形转圈 android:useLevel="false" android:startColor="#F7F7F7" android:centerColor="#F7F7F7" android:centerY="0.50" android:endColor="#B3B4B4" /> </shape> </rotate>