1.可以动的蜗牛进度条(seekbar):https://github.com/android-cjj/SnailBar
边框就是设置seekbar的background为一个sharp或一个.9图片
进度条就是一个layerlist
thumb设置成一个动画:
xml version="1.0" encoding="utf-8"?>seekbar的thumb设置为这个逐帧动画:xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> - android:drawable="@drawable/s1" android:duration="300" />
- android:drawable="@drawable/s2" android:duration="300" />
- android:drawable="@drawable/s3" android:duration="300" />
- android:drawable="@drawable/s4" android:duration="300" />
- android:drawable="@drawable/s5" android:duration="300" />
android:thumb="@drawable/snailanim"
android:paddingBottom="3px">
android:centerColor="#ffdeeaeb"
android:endColor="#ffd9e5e6"
android:centerY="0.45"
android:angle="270"/>
android:paddingBottom="3px" >
android:centerColor="#ffdfffc5"
android:endColor="#ff87f31a"
android:centerY="0.45"
android:angle="270"/>
2.纵向的progressbar:
xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android"> - android:id="@android:id/background">
android:radius="5dip" /> android:startColor="#ff9d9e9d" android:centerColor="#ff5a5d5a" android:centerY="0.75" android:endColor="#ff747674" android:angle="270" /> - android:id="@android:id/secondaryProgress">
android:clipOrientation="vertical" android:gravity="bottom"> android:radius="5dip" /> android:startColor="#80ffd300" android:centerColor="#80ffb600" android:centerY="0.75" android:endColor="#a0ffcb00" android:angle="270" /> - android:id="@android:id/progress">
android:clipOrientation="vertical" android:gravity="bottom"> android:radius="5dip" /> android:startColor="#ffffd300" android:centerColor="#ffffb600" android:centerY="0.75" android:endColor="#ffffcb00" android:angle="270" />
clip的clipOrientation指定进度条是横向还是竖向,默认是横向,gravity属性指定对齐方式,默认是竖向中间横向靠左
android:indeterminateOnly="false"
android:indeterminateDrawable="@drawable/animlist_vprogressbar"
android:progressDrawable="@drawable/layerlist_vprogress"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:id="@+id/progressBar"
android:minWidth="10dp"
android:maxWidth="10dp"
android:progress="30"
android:layout_centerInParent="true"
/>
indeterminateOnly:是模糊的还是精细的进度,true时为模糊进度条,fasle为水平或垂直精确进度条
android:indeterminateDrawable:表示模糊进度的逐帧动画,此处可以不指定,当然,也可以指定indeterminateOnly为true,这样这个动画就可以起作用了
layout_height/width:竖向时指定具体高度,宽度可以为wrap_content
min/maxwidth:如果是横向的,指定的就是min/maxheight,指定这个,让进度条粗细合适
3.模糊进度也可以用横向的进度条显示出来:
style="?android:attr/progressBarStyleHorizontal"
android:indeterminateOnly="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:minWidth="10dp"
android:maxWidth="10dp"
android:progress="30"
/>
如下面那个进度条显示的那样:
4.三种自定义圆形进度条的方式:
4.1.使用逐帧动画:
动画drawable:
xml version="1.0" encoding="utf-8"?>android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> - android:duration="150" android:drawable="@drawable/loading_01" />
- android:duration="150" android:drawable="@drawable/loading_02" />
- android:duration="150" android:drawable="@drawable/loading_03" />
- android:duration="150" android:drawable="@drawable/loading_04" />
- android:duration="150" android:drawable="@drawable/loading_05" />
- android:duration="150" android:drawable="@drawable/loading_06" />
- android:duration="150" android:drawable="@drawable/loading_07" />
布局:
xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal"> android:id="@+id/loading_process_dialog_progressBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminate="true" android:indeterminateDrawable="@drawable/loading" />
4.2.使用sharp:
drawable下新建xml,以rotate为根节点:
xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360"> android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="8" android:useLevel="false"> android:centerColor="#FFDC35" android:centerY="0.50" android:endColor="#CE0000" android:startColor="#FFFFFF" android:type="sweep" android:useLevel="false" />
直接用shape不会旋转
布局文件一样
4.3.使用图片:
drawable下新建xml:
xml version="1.0" encoding="utf-8"?>或:android:drawable="@drawable/dialog_progress_round" android:fromDegrees="0.0" android:toDegrees="360.0" android:pivotX="50.0%" android:pivotY="50.0%" xmlns:android="http://schemas.android.com/apk/res/android" />
xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android"> android:drawable="@drawable/dialog_progress_round" android:fromDegrees="0.0" android:pivotX="50.0%" android:pivotY="50.0%" android:toDegrees="360.0" />
布局文件一样
以上都没有指定style,默认style是:style="?android:attr/progressBarStyle"
如果要放大,可以用:progressBarStyleLarge,缩小用:progressBarStyleSmall