标签:
效果图:
修改progressbar 让他满足自己的需求一般来说只修改一下,progressbar的style就可以满足需求了:
activity代码:仅仅显示一个布局而已
package com.example.testcustomprogressbar; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.testcustomprogressbar.MainActivity" > <ProgressBar android:id="@+id/my_customprogressbar1" style="@style/mycustom_progressbar1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> <ProgressBar android:id="@+id/my_customprogressbar2" style="@style/mycustom_progressbar2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/my_customprogressbar1" android:layout_below="@+id/my_customprogressbar1" android:layout_marginTop="26dp" /> <ProgressBar android:id="@+id/my_customprogressbar3" style="@style/mycustom_progressbar3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/my_customprogressbar2" android:layout_below="@+id/my_customprogressbar2" android:layout_marginTop="26dp" /> <ProgressBar android:id="@+id/my_customprogressbar4" style="@style/mycustom_progressbar_hor" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_below="@+id/my_customprogressbar3" android:layout_centerHorizontal="true" android:layout_marginTop="22dp" android:max="100" android:progress="40" android:secondaryProgress="60" /> <ProgressBar android:id="@+id/my_customprogressbar5" style="@style/mycustom_progressbar_hor2" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_alignLeft="@+id/my_customprogressbar4" android:layout_below="@+id/my_customprogressbar4" android:layout_marginTop="26dp" android:max="100" android:progress="40" android:secondaryProgress="60" /> </RelativeLayout>
style的代码:
<style name="mycustom_progressbar1"> <item name="android:indeterminateDrawable">@drawable/progressbar_ver_image</item> <item name="android:minHeight">30dp</item> <item name="android:minWidth">30dp</item> <item name="android:maxHeight">60dp</item> <item name="android:maxWidth">60dp</item> </style>
<?xml version="1.0" encoding="utf-8"?> <!-- 定义一个旋转的动画 ,图片是我们自定义的--> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/resizeapi" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" > </rotate>
第二种圆形progressbar 使用一个动画:
style:
<style name="mycustom_progressbar2"> <item name="android:indeterminateDrawable">@drawable/progressbar_ver_animation</item> <item name="android:minHeight">60dp</item> <item name="android:minWidth">60dp</item> <item name="android:maxHeight">100dp</item> <item name="android:maxWidth">100dp</item> </style>
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/ok1" android:duration="250"/> <item android:drawable="@drawable/ok2" android:duration="250"/> <item android:drawable="@drawable/ok3" android:duration="250"/> <item android:drawable="@drawable/ok4" android:duration="250"/> </animation-list>
第三种圆形progressbar 使用shape来构建drawable:
<style name="mycustom_progressbar3"> <item name="android:indeterminateDrawable">@drawable/progressbar_ver_shape</item> <item name="android:minHeight">60dp</item> <item name="android:minWidth">60dp</item> <item name="android:maxHeight">100dp</item> <item name="android:maxWidth">100dp</item> </style>
<?xml version="1.0" encoding="utf-8"?> <!-- 定义一个旋转的动画 ,图片是我们自定义的shape --> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" > <shape android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="8" android:useLevel="false" > <gradient android:centerColor="#FFFFFF" android:centerY="0.50" android:endColor="#1E90FF" android:startColor="#000000" android:type="sweep" android:useLevel="false" /> </shape> </rotate>
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background"> <shape> <corners android:radius="5dip" /> <gradient android:startColor="#ffff0000" android:centerColor="#ffff0000" android:centerY="0.75" android:endColor="#ffff0000" android:angle="270" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <corners android:radius="5dip" /> <gradient android:startColor="#800000ff" android:centerColor="#800000ff" android:centerY="0.75" android:endColor="#800000ff" android:angle="270" /> </shape> </clip> </item> <item android:id="@android:id/progress" > <clip > <shape> <corners android:radius="5dip" /> <gradient android:startColor="#ff00ff00" android:centerColor="#ff00ff00" android:centerY="0.75" android:endColor="#ff00ff00" android:angle="270" /> </shape> </clip> </item> </layer-list>
background:
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="5dip" /> <gradient android:angle="270" android:centerColor="#ffff0000" android:centerY="0.75" android:endColor="#ffff0000" android:startColor="#ffff0000" /> </shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="5dip" /> <gradient android:angle="270" android:centerColor="#ff00ff00" android:centerY="0.75" android:endColor="#ff00ff00" android:startColor="#ff00ff00" /> </shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="5dip" /> <gradient android:angle="270" android:centerColor="#800000ff" android:centerY="0.75" android:endColor="#800000ff" android:startColor="#800000ff" /> </shape>
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@android:id/background" android:drawable="@drawable/progressbar_hor_bg"> </item> <item android:id="@android:id/secondaryProgress"> <clip android:drawable="@drawable/progressbar_hor_second_progress" > </clip> </item> <item android:id="@android:id/progress"> <clip android:drawable="@drawable/progressbar_hor_progress" > </clip> </item> <!-- progress 这个地方原作者写的是一个点9的图--> <!-- <item android:id="@android:id/progress"> <clip> <nine-patch android:src="@drawable/progress_patch_galy" /> </clip> </item> --> </layer-list>
嘿嘿..最后,做人要厚道:神一般男人的原博主博文连接http://blog.csdn.net/mad1989/article/details/38042875
对了,代码还是贴上来吧.总感觉在ide中直接看代码会更舒服一些:http://download.csdn.net/detail/u010399316/9000197
版权声明:本文为博主原创文章,未经博主允许不得转载。
android 自定义水平和圆形progressbar 只定义一些style就可以
标签:
原文地址:http://blog.csdn.net/u010399316/article/details/47611319