ProgressBar直接继承View,在样式展示上有两种方式,横向和圆形,这里主要介绍自定义进度条的展示。
1、对于水平进度条,android默认的进度条颜色是黄色,如果想用其他的颜色代替。可以自定义颜色。
progressbg.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" android:drawable="@drawable/jindu"/>
</layer-list>
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="412dp"
android:layout_height="24dp"
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="@drawable/progressbg"
android:background="@drawable/di"
android:layout_marginBottom="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
这里你可以添加两张有关进度条的图片,一张是底图,一张是进度条的图。在对ProgressBar中对进度条的定义中,进度条的
宽是412dp,高是24dp,这里也可以随你定义大小,但是请注意,此大小最好跟你图片的宽高信息一样,并且,放在对应的drawable文件夹下,
1、对于水平进度条,android默认的进度条颜色是黄色,如果想用其他的颜色代替。可以自定义颜色。
progressbg.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" android:drawable="@drawable/jindu"/>
</layer-list>
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="412dp"
android:layout_height="24dp"
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="@drawable/progressbg"
android:background="@drawable/di"
android:layout_marginBottom="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
这里你可以添加两张有关进度条的图片,一张是底图,一张是进度条的图。在对ProgressBar中对进度条的定义中,进度条的
宽是412dp,高是24dp,这里也可以随你定义大小,但是请注意,此大小最好跟你图片的宽高信息一样,并且,放在对应的drawable文件夹下,
高分辨率的设备就放在hdip下面,中等分辨率的就放在mdip下面。
2、圆形进度条
这以ImageView来实现播放动画,代码如下:
res/anim/anim.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/c1" android:duration="100"/>
<item android:drawable="@drawable/c2" android:duration="100"/>
<item android:drawable="@drawable/c3" android:duration="100"/>
<item android:drawable="@drawable/c4" android:duration="100"/>
<item android:drawable="@drawable/c5" android:duration="100"/>
<item android:drawable="@drawable/c6" android:duration="100"/>
<item android:drawable="@drawable/c7" android:duration="100"/>
<item android:drawable="@drawable/c8" android:duration="100"/>
</animation-list>
ImageView
android:id="@+id/progress2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@anim/anim"
/>
ImageView mProgress2 ;
AnimationDrawable animationDrawable=(AnimationDrawable) mProgress2.getBackground();
animationDrawable.start();