如何降低自定义进度条的速度

7
我已经实现了一个自定义进度条,当从一个URL获取数据时显示它,进度条旋转得很好,但我的问题是我找不到一个合适的方法来降低它的旋转速度,目前它旋转得非常快。
请用你的建议和回复来帮助我。
进度条的XML布局:
  <ProgressBar
        android:id="@+id/showProgress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:indeterminateDrawable="@drawable/my_progress_indeterminate" />

此外,这里还有一个“my_progress_indeterminate”,用于旋转我的自定义进度条:
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/image_loading"
    android:pivotX="50%"
    android:pivotY="50%" />

请分享一些例子,如果可能的话要减少旋转速度。
任何建议都将不胜感激。
3个回答

6

请试试这个。它会帮助你。

创建 progressbar_custom.xml 文件

/res/drawable/progressbar_custom.xml:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="3000"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" >

    <shape
        android:innerRadius="18dp"
        android:shape="ring"
        android:thickness="5dp"
        android:useLevel="false" >
        <size
            android:height="48dp"
            android:width="48dp" />

        <gradient
            android:centerColor="#802A67AD"
            android:centerY="0.5"
            android:endColor="#ff2A67AD"
            android:startColor="#002A67AD"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>

在XML文件中添加进度条
 <ProgressBar
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:indeterminateDrawable="@drawable/progressbar_custom" />

6

添加代码到progress.xml文件中

android:fromDegrees="0"

android:toDegrees="1080"   <!-- Add in code to progress custumize xml to speed up -->

1
使用“rotate”替代“animated-rotate”,并更改android:toDegrees或android:toDegress可以使它变得更慢。
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/image_loading"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接