确定进度条的样式很容易,有很多教程可以实现这一点。这是我正在使用的:
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="8dp"
android:background="@drawable/progress_background"
android:progressDrawable="@drawable/progress"
android:id="@+id/progressBar" />
可绘制的progress_background.xml
:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="@color/colorAccent" />
<corners android:radius="4dp" />
</shape>
</clip>
</item>
</layer-list>
它看起来像这样:
![enter image description here](https://i.stack.imgur.com/g1nCS.png)
但是,当尚未取得进展时,我想使用不确定的进展。所以我尝试:
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="8dp"
android:background="@drawable/progress_background"
android:progressDrawable="@drawable/progress"
android:indeterminateTint="@color/colorAccent"
android:indeterminateTintMode="src_in"
android:indeterminate="true"
android:id="@+id/progressBar" />
但不确定的进度不会延伸到条形高度:
![enter image description here](https://i.stack.imgur.com/K9Zo0.png)
我也尝试使用可绘制文件对其进行样式设置,但它看起来像是损坏的确定进度条(再次从 0 填充到 100)。
所需的不确定进度条应该看起来像常规进度条,但具有 8dp 高度和圆角。
默认不确定进度条动画使用非 9-patch png。所以它不能拉伸超过 8dp 高度的进度条。你应该添加android:indeterminateDrawable
带有自定义动画:
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/progressbar_indeterminate1" android:duration="50" />
<item android:drawable="@drawable/progressbar_indeterminate2" android:duration="50" />
<item android:drawable="@drawable/progressbar_indeterminate3" android:duration="50" />
...
<item android:drawable="@drawable/progressbar_indeterminateX" android:duration="50" />
</animation-list>
然后制作可绘制的动画,如下所示(可以是 xml、图像或 9-patch):
动画帧1
动画帧2
android (api21+) 的版本绝不会使用 AnimatedVectorDrawable 来表示不确定的 ProgressBar。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)