Android之自定义进度条

第一种方式完全自定义


Android进度条有4种风格可以使用。
默认值是progressBarStyle。
设置成progressBarStyleSmall后,图标变小。 
设置成progressBarStyleLarge后,图标变大
设置成progressBarStyleHorizontal后,变成横向长方形。

style文件

<style name="CustomProgressStyle" parent="@android:style/Widget.ProgressBar.Small">        <item name="android:minWidth">100dip</item>        <item name="android:maxWidth">100dip</item>        <item name="android:minHeight">100dip</item>        <item name="android:maxHeight">100dip</item>    </style>
shape文件
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >    <item>        <rotate            android:drawable="@drawable/bar_code_round"            android:fromDegrees="0.0"            android:pivotX="50.0%"            android:pivotY="50.0%"            android:toDegrees="360.0" />    </item></layer-list>
布局文件

<ProgressBar        android:id="@+id/codemain_pb"        style="@style/CustomProgressStyle"        android:layout_width="240dp"        android:layout_height="240dp"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true"        android:indeterminate="true"        android:indeterminateDrawable="@drawable/background_icon_pic" />

如果你想实现自定义进度条风格,你只用跟着android源代码的例子创建一个自定义的风格。你需要将android:indeterminateDrawable替换成你想要的。

<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="#ff9d9e9d"                android:centerColor="#ff5a5d5a"                android:centerY="0.75"                android:endColor="#ff747674"                android:angle="270"        />    </shape></item><item android:id="@android:id/secondaryProgress">    <clip>        <shape>            <corners android:radius="5dip" />            <gradient                    android:startColor="#80ffd300"                    android:centerColor="#80ffb600"                    android:centerY="0.75"                    android:endColor="#a0ffcb00"                    android:angle="270"            />        </shape>    </clip></item><item    android:id="@android:id/progress">    <clip>        <shape>            <corners                android:radius="5dip" />            <gradient                android:startColor="@color/progress_start"                android:endColor="@color/progress_end"                android:angle="270" />        </shape>    </clip></item></layer-list>

第二种使用帧动画的方式(一张张图片替换的形式)

<?xml version="1.0" encoding="UTF-8"?>  <animation-list android:oneshot="false"  xmlns:android="http://schemas.android.com/apk/res/android">    <item android:duration="150" android:drawable="@drawable/loading_01" />    <item android:duration="150" android:drawable="@drawable/loading_02" />    </animation-list>   




更多相关文章

  1. Android studio project文件结构翻译
  2. Eclipse中Android项目XML文件的格式化配置
  3. Android找不到Manifest系统文件
  4. androidUI设计之旅 ----布局文件属性解析
  5. 制作linux根文件系统
  6. android 更改密码显示风格
  7. android中如何获取文件的路径总结
  8. Android的xml文件中引用类型

随机推荐

  1. SQL Server误区30日谈 第14天 清除日志后
  2. SQL Server误区30日谈 第13天 在SQL Serv
  3. SQL Server误区30日谈 第12天 TempDB的文
  4. SQL Server误区30日谈 第11天 镜像在检测
  5. SQL Server误区30日谈 第10天 数据库镜像
  6. SQL Server误区30日谈 第9天 数据库文件
  7. SQL Server误区30日谈 第8天 有关对索引
  8. SQL Server误区30日谈 第7天 一个实例多
  9. SQL Server误区30日谈 第6天 有关NULL位
  10. SQL Server误区30日谈 第5天 AWE在64位SQ