android上不确定水平进度条的样式
确定进度条的样式很容易,有很多教程可以实现这一点。这是我正在使用的:android上不确定水平进度条的样式,android,android-styles,android-progressbar,Android,Android Styles,Android Progressbar,确定进度条的样式很容易,有很多教程可以实现这一点。这是我正在使用的: <ProgressBar style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="8dp" android:background="@drawable/progress_background" android:progres
<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" />
看起来是这样的:
但当进度还不可用时,我想使用不确定的。所以我试着:
<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" />
但不确定进度不会延伸到钢筋高度:
我也尝试使用可绘制文件对其进行样式设置,但它看起来像断开的确定进度条(再次从0填充到100)
所需的不确定进度条应与常规进度条类似,但具有8dp高度和圆角。默认不确定进度条动画使用非9面片PNG。所以它不能在你的8dp高度进度条上伸展。您应该添加带有自定义动画的android:UndeterminatedRavable:
<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>
android(api21+)的任何版本都不会使用AnimatedVectorDrawable进行不确定的进度栏。我看到很多人都在看这篇文章,所以我想我应该编辑它并分享一个例子:
注意(这个例子并不完整,它仍在进行中,但我想这是一个起点)
GitHub:
本例中的重要部分如下:在drawable中创建一个xml文件custom\u progress\u bar\u horizontal.xml,并添加以下内容
<?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>
<padding
android:bottom="3dip"
android:top="3dip"
android:left="3dip"
android:right="3dip"/>
<corners
android:radius="5dip" />
<gradient
android:startColor="#2a2b2f"
android:centerColor="#2a2b2f"
android:centerY="0.50"
android:endColor="#2a2b2f"
android:angle="270" />
</shape>
</item>
<item
android:id="@android:id/progress">
<clip>
<shape>
<corners
android:radius="5dip" />
<gradient
android:startColor="#ff0e75af"
android:endColor="#ff1997e1"
android:angle="90" />
</shape>
</clip>
</item>
</layer-list>
在styles.xml中添加以下代码
<style name="CustomProgressBar" parent="android:Widget.ProgressBar.Horizontal">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">@drawable/custom_progress_bar_horizontal</item>
<item name="android:minHeight">10dip</item>
<item name="android:maxHeight">20dip</item>
</style>
假的
@可绘制/自定义进度条水平
10度
20度
在活动布局中添加样式后,添加:
<ProgressBar
android:id="@+id/customProgress"
style="@style/CustomProgressBar"
android:layout_width="match_parent"/>
下面的进度显示在一个框架中,这有点棘手,因为您需要扩展ProgressBar类并在那里进行更改
我将在这里留下一些示例,并通知何时将它们添加到github项目中
如果你想以自己的方式破坏进度,最好的例子是:
其他进度条示例:
有关更多详细信息,请访问此处 是的。“我也尝试使用可绘制文件来设置它的样式,但它看起来像断了的确定进度条(再次从0填充到100)。”-我没有提供代码(这是罪过),但我尝试了OK。我没注意到。要完成这项工作,你必须制作自己的自定义动画和一堆png文件。我会改变我的答案。
<ProgressBar
android:id="@+id/customProgress"
style="@style/CustomProgressBar"
android:layout_width="match_parent"/>