Android自定义ProgressBar不旋转

时间:2012-11-11 15:43:53

标签: android animation rotation progress-bar

我想更改ProgressBar的默认动画,所以我在主题中添加了自定义样式:

styles.xml

<style name="ProgressTheme" parent="@android:style/Widget.ProgressBar.Large">
    <item name="android:indeterminateDrawable">@drawable/spinner_holo_light</item>
</style>

我在ProgressBar中使用以下内容调用此样式:

ProgressBar.xml

<ProgressBar
    android:id="@+id/loadingProgressBar"
    style="@style/ProgressTheme"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

问题出在spinner_holo_light.xml

如果我使用以下内容,一切在使用os 3.0+的设备上运行正常,但进度不会在旧的os版本上轮换:

spinner_holo_light.xml

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/spinner_76_inner_holo"
    android:fromDegrees="720"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="0" />

但是如果我使用animate-rotate代替,那么动画适用于每个操作系统版本,但结果是一个非常迟钝的动画。

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/spinner_76_inner_holo"
    android:fromDegrees="720"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="0" />

你怎么看?我在这里做错了吗?

4 个答案:

答案 0 :(得分:11)

在较早的设备上,当android:fromDegrees大于android:toDegress中的<rotate>时,这是一个问题。尝试交换值:

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/spinner_76_inner_holo"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="720" />

或者,您可以尝试将其设置为无限:

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/spinner_76_inner_holo"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite" />

旧设备上的动画可能会滞后。要解决这个问题,请将android:animationResolution添加到样式中:

<style name="ProgressTheme" parent="@android:style/Widget.ProgressBar.Large">
    <item name="android:indeterminateDrawable">@drawable/spinner_holo_light</item>
    <item name="android:animationResolution">33</item>
</style>

答案 1 :(得分:1)

制作进度对话框的透明背景。

使边框减少进度对话框。

定制圆形进度对话框的微调器颜色。

http://pankajchunchun.wordpress.com/2011/09/10/customization-of-spinner-progress/

答案 2 :(得分:0)

即使添加

,我也无法在三星Galaxy S Plus上运行
<item name="android:animationResolution">33</item>

我问的问题类似于你的回应@Tomik

Android Progress Bar slow rotation on pre HoneyComb devices

确定所有预蜂窝设备是否顺畅?

答案 3 :(得分:0)

我通过将BackGround xml自定义格式更改为indeterminateDrawable解决了这个问题

  

使用 android:indeterminateDrawable ,但 android:BackGround

    <ProgressBar
    android:layout_centerHorizontal = "true"
    android:layout_centerVertical = "true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:indeterminateDrawable = "@drawable/progressbar"
    android:id="@+id/progressBar"        
    android:indeterminate = "true"/>

和自定义进度栏XML代码

<?xml version="1.0" encoding="utf-8" ?>

 <rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360">

     <shape android:shape="ring" android:innerRadiusRatio="3"
        android:thicknessRatio="7" android:useLevel="false">

        <size android:width="76dip" android:height="76dip" />
           <gradient android:type="sweep" android:useLevel="false"
            android:startColor="@android:color/transparent"
            android:endColor="#00FF00"
            android:angle="0" />
    </shape>
</rotate>  
相关问题