确定进度条的样式很容易,有很多教程可以实现。这是我正在使用的:
<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>
看起来像这样:
但是当还没有进展时,我想使用不确定的。所以我尝试了:
<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" />
但不确定的进度不会拉伸(stretch)到条形高度:
我也尝试使用可绘制文件来设计它的样式,但它看起来像是损坏的确定进度条(再次从 0 填充到 100)。
所需的不确定进度条应该看起来像常规进度条,但具有 8dp 高度和圆角。
最佳答案
默认的不确定进度条动画使用非 9 补丁 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):
android (api21+) 的任何版本都不会为不确定的 ProgressBar 使用 AnimatedVectorDrawable。
关于android - 在android上设计不确定的水平进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35514741/