2010-12-05 82 views
49

我在Android代码中做了一些挖掘,并看到了在不确定进度条中的使用。试图创建自己绘制这个标签后:Android Animate旋转

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:drawable="@drawable/spinner_pia" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:framesCount="12" 
    android:frameDuration="100" /> 

我得到一个错误: “发现在包‘机器人’属性‘frameDuration’无资源标识符” - 这意味着frameDuration是私有属性。 有没有办法使用这种“动画旋转”功能?

我的任务是替换系统的默认不确定进度条。我想用尽可能少的代码来完成它(如果可能,只需更改几个属性)。 使用进度视图,设置:

android:indeterminateOnly="true" 
android:indeterminateBehavior="cycle" 
android:indeterminateDuration="3500" 
android:indeterminateDrawable="@drawable/pia_sivuvator" 

点“@绘制/ pia_sivuvator”该对象会一直让我的任务,因为优雅的,因为他们来了,但我卡上的私有属性。

有帮助吗?

+1

有同样的问题。排除参数(`framesCount`和`frameDuration`)没有多大帮助。动画有效,但对我来说看起来不太好(动画不平滑,像低帧率)。 在这个问题上创建了一个问题http://code.google.com/p/android/issues/detail?id=19248 – 2011-08-14 18:35:11

回答

57

我遇到了完全相同的问题。您可以排除这些参数(framesCount和frameDuration),它可能适用于您。我试图排除它们,它的动画很好,但我设置的宽度/高度没有得到尊重,所以我最终创建了一个简单的旋转动画和一个ImageView来应用它。这里的动画文件(RES /阿尼姆/ clockwise_rotation.xml):

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

然后你只是抬高你的动画,设置重复计数,并从查看启动

Animation rotation = AnimationUtils.loadAnimation(this, R.anim.clockwise_rotation); 
rotation.setRepeatCount(Animation.INFINITE); 
myView.startAnimation(rotation); 
+24

如果你想要在xml中使用`android:repeatCount =“infinite”`而不是硬代码 – pleerock 2012-10-16 04:44:58

+0

使用framesCount参数请参阅http://stackoverflow.com/questions/3760381/rotating-image-animation-list-or-animated-rotate-android/14996762#14996762 – vokilam 2013-02-21 07:34:07

6

我不知道如何解决私有属性,我有同样的问题。

通过,如果你想改变进度的这些属性的方式:

android:indeterminateOnly="true" 
android:indeterminateBehavior="cycle" 
android:indeterminateDuration="3500" 
android:indeterminateDrawable="@drawable/pia_sivuvator" 

您可以使用样式框架在values/styles.xml文件中定义扩展标准的Android一个进度条样式很容易做到这一点:

<style name="YourProgressBarStyle" parent="@android:style/Widget.ProgressBar"> 
     <item name="android:indeterminateDrawable">@drawable/progress_bar_indeterminate</item> 
</style> 

然后将它应用到xml布局文件中的进度条。

... 
<ProgressBar 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    style="@style/YourProgressBarStyle"/> 
... 
5

我使用这个可绘制的XML解决了这个问题。虽然它只是似乎是顺利在Android的新版本:

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

你能解释你从这个RotateDrawable做什么? http://stackoverflow.com/questions/5872257/how-do-i-use-rotatedrawable – rds 2012-10-31 21:26:17

7

而不是创造的动画(需要更多代码,不仅XML配置),使用layer-list作为可绘制资源。 有趣的是layer-listanimated-rotate更流畅。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item> 
    <rotate 
     android:drawable="@drawable/spinner_loading" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:fromDegrees="0" 
     android:toDegrees="360"/> 
</item> 
</layer-list> 

那当然使用它的样式,马里奥Lenci写道:

<style name="YourProgressBarStyle" parent="@android:style/Widget.ProgressBar"> 
    <item name="android:indeterminateDrawable">@drawable/progress_bar_indeterminate</item> 
</style>