2009-11-26 36 views
7

我在將視頻應用於視圖時遇到問題。我正嘗試從CursorAdapter的構造函數中加載動畫,以便稍後將其分配給列表中的某些子項。Android Frame by Frame CursorAdapter中的元素動畫問題

在構造函數中,我有:

shineAnimation = AnimationUtils.loadAnimation(ctx, R.anim.news_list_item_shine); 

動畫在我的RES /阿尼姆DIR

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"> 
    <item android:drawable="@drawable/shine1" android:duration="200" /> 
    <item android:drawable="@drawable/shine2" android:duration="200" /> 
    <item android:drawable="@drawable/shine3" android:duration="200" /> 
    <item android:drawable="@drawable/shine4" android:duration="200" /> 
    <item android:drawable="@drawable/shine5" android:duration="200" /> 
</animation-list> 

我得到一個異常: 未知的動畫名稱:動畫列表

幫助將不勝感激

謝謝 š

回答

2

我不認爲你通過AnimationUtils加載AnimationDrawablesAnimationDrawableDrawable多於它是Animation。從SDK指南中嘗試this sample code

ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image); 
    rocketImage.setBackgroundResource(R.anim.rocket_thrust); 
    rocketAnimation = (AnimationDrawable) rocketImage.getBackground(); 
+0

嗨, 謝謝回答,那是你再是不是馬克:) 我沒有嘗試並使用setBackgroundResource的原因是,我懷疑會導致動畫的運行我認爲的背景。我想我可以通過在所有其他元素之前放置一個空的ImageView並使用setBackgroundResource()來解決這個問題? – Pandalover 2009-11-26 13:52:03

+0

您可能不必將其用作背景,但我認爲您必須將其用作Drawable而不是動畫。試試你的ImageView setImageResource()而不是setBackgroundResource(),或者其他的東西。 – CommonsWare 2009-11-26 14:52:55