2011-11-05 83 views
0

我想要在2.2版本的機器上使用eclipse來運行android 2.2上的幀動畫,並且我無法讓它運行。它剛好在動畫的第一幀上。Android動畫沒有播放

這裏是我的活動代碼:

public class SpriteAnimationActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     ImageView lView = (ImageView) findViewById(R.id.imageView1); 
     AnimationDrawable lAnimation = (AnimationDrawable)lView.getBackground(); 
     lAnimation.start(); 
    } 
} 

這裏是我的動畫列表的XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="false" > 
    <item android:drawable="@drawable/a1" android:duration="100" /> 
    <item android:drawable="@drawable/a2" android:duration="100" /> 
    <item android:drawable="@drawable/a3" android:duration="100" />  
</animation-list> 

我用我的主屏幕上的ImageView小部件設置背景中顯示的圖像。我想在這裏遵循的指導http://developer.android.com/guide/topics/graphics/drawable-animation.html,但我似乎無法得到它的工作

+0

您的動畫是否有效?否則我有一個解決方案。 –

回答

1

你必須開始動畫...

ImageView lView = (ImageView) findViewById(R.id.imageView1); 

      lView.setBackgroundResource(R.drawable.my_animation_list); 
      final AnimationDrawable lAnimation = (AnimationDrawable)lView.getBackground(); 


    //  Button btn= 
      findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        lAnimation.start(); 
       } 
      }); 
0

你必須sta通過按鈕點擊監聽器手動執行動畫或使用下面的onWindowFocusChange監聽器

public void onWindowFocusChanged(boolean hasFocus) { 
    super.onWindowFocusChanged(hasFocus); 
    if(hasFocus) { 
     lAnimation.start(); 
    } 
} 
+0

如何更改editview的光標顏色 – Venkat