2011-07-04 18 views
0

画面に何も表示されません。個々のpngがうまくレンダリングされます。なにが問題ですか?レイアウトアニメーションが空白

<ImageButton 
    android:id="@+id/btn_loading" 
    android:src="@drawable/loading_animation" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

そして次は、ファイル "loading_animation.xml" です:あなたはアニメーション

使用Javaコードに次のコードを開始に持って

<?xml version="1.0" encoding="utf-8"?> 
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
     android:oneshot="false" 
     android:repeatMode="repeat" > 
     <item android:drawable="@drawable/load0" android:duration="20" /> 
     <item android:drawable="@drawable/load1" android:duration="20" /> 
     <item android:drawable="@drawable/load2" android:duration="20" /> 
     <item android:drawable="@drawable/load3" android:duration="20" /> 
     <item android:drawable="@drawable/load4" android:duration="20" /> 
     <item android:drawable="@drawable/load5" android:duration="20" /> 
     <item android:drawable="@drawable/load6" android:duration="20" /> 
     <item android:drawable="@drawable/load7" android:duration="20" /> 
     <item android:drawable="@drawable/load8" android:duration="20" /> 
    </animation-list> 

答えて

1

import java.util.Timer; 
import java.util.TimerTask; 

import android.app.Activity; 
import android.graphics.drawable.AnimationDrawable; 
import android.os.Bundle; 
import android.widget.ImageView; 

public class Main extends Activity { 



    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.myxml); 

     ImageView animation = (ImageView) findViewById(R.id.btn_loading); 

     animation.setBackgroundResource(R.drawable.loading_animation); 

     AnimationRoutine animationRoutine = new AnimationRoutine(); 

     Timer t = new Timer(false); 

     t.schedule(animationRoutine, 100); 

    } 

    private class AnimationRoutine extends TimerTask { 

     AnimationRoutine() { 
     } 

     public void run() { 

      ImageView img = (ImageView) findViewById(R.id.btn_loading); 

      AnimationDrawable frameAnimation = (AnimationDrawable) img 
        .getBackground(); 

      frameAnimation.start(); 

     } 

    } 

} 
+0

ありがとうございます!私は、これを行うには、Eclipse GUIツールの方法があるのだろうか? – hunterp