2010-12-05 81 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>