Android自定义进度条
16lz
2021-01-23
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>
更多相关文章
- Android studio project文件结构翻译
- Eclipse中Android项目XML文件的格式化配置
- Android找不到Manifest系统文件
- androidUI设计之旅 ----布局文件属性解析
- 制作linux根文件系统
- android 更改密码显示风格
- android中如何获取文件的路径总结
- Android的xml文件中引用类型