2011-07-28 39 views
0

我正在使用handler來簡單地發佈延遲的時間間隔,循環訪問一系列可繪製資源並相應地設置imageResource。它工作得很好,但「動畫」不是非常流暢。有沒有其他的方式來實現這種類型的動畫,我只是翻閱像翻書一樣的圖像?更好的實現翻書風格動畫的方法?

回答

0

你想在Android中稱爲「幀動畫」。圖像和顯示在屏幕上的時間在XML文件中定義。詳情請參閱以下鏈接:

http://developer.android.com/guide/topics/resources/animation-resource.html#Frame

這裏是我有它在快速測試程序,我寫了運行:

setContentView(R.layout.main); 
    ImageView rocketImage = (ImageView) findViewById(R.id.imageView1); 
    rocketImage.setBackgroundResource(R.drawable.jena); 
    rocketAnimation = (AnimationDrawable) rocketImage.getBackground(); 

然後,我繪製文件夾內我有jena.xml :

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="false"> 
    <item android:drawable="@drawable/jenaveve0000" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0001" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0002" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0003" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0004" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0005" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0006" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0007" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0008" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0031" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0032" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0033" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0034" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0035" android:duration="500"/> 
<item android:drawable="@drawable/jenaveve0036" android:duration="500"/> 
</animation-list> 

啓動動畫,我有:

public void onWindowFocusChanged(boolean hasFocus) { 
    // TODO Auto-generated method stub 
    super.onWindowFocusChanged(hasFocus); 
    rocketAnimation.start(); 
+0

這絕對是它,但由於某種原因,它拒絕工作。我以編程方式完成它,比如animationDrawable.addFrame ...然後調用start(),但它只顯示第一幀。我很好,我使用我的處理程序。 (AnimationDrawable本身可能只是使用Handler本身,儘管我沒有仔細查看@源代碼) – LuxuryMode

0

請看看如下: http://code.google.com/p/android-page-curl/

我覺得這個頁面捲曲效果是很大的。

+0

謝謝outman。 Flipbook可能是一個誤導性的術語。我不需要翻頁效果。我只是一個接一個地設置圖像以賦予移動動畫的效果。每幅圖像都略有不同......你知道我的意思。只是想知道是否有一些優化或不同的方法來使這個更平滑。 – LuxuryMode

+0

我明白你的意思。可以位圖或可繪製的緩存幫助你嗎?就像WeakHashMap mCache = new WeakHashMap ();啓動後臺線程來維護緩存並從緩存中加載映像。 – outman