0

フレームごとのアニメーションを実行しようとしていますが、AVD でアプリをシミュレートするたびにエラーが発生し、強制終了します。コードは正しいと思います。

これは私のコードです:

public class MainJugadaposte extends Activity  {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_jugadaposte);

    this.Botonplay();

}

 private void Botonplay() {
       Button b = (Button)this.findViewById(R.id.ImButton1);
       b.setOnClickListener(new Button.OnClickListener() {
             public void onClick(View v) {
                 animate();
             } 
          });
       }


   private void animate() {
          ImageView imgView = (ImageView)findViewById(R.id.imageAnimation);                                        
          imgView.setVisibility(ImageView.VISIBLE);
          imgView.setBackgroundResource(R.drawable.frame_animation);

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

          if (frameAnimation.isRunning()) {
             frameAnimation.stop();
          }
          else {
             frameAnimation.stop();
             frameAnimation.start();
          }
       }

ボタンを押すとアニメーションが始まります。

で、これがレイアウト。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/imageAnimation"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:adjustViewBounds="true" />

 <ImageButton
    android:id="@+id/ImButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imagen"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="17dp"
    android:layout_marginLeft="26dp"
    android:background="#FFCC66"
    android:clickable="true"
    android:src="@drawable/play" />

</RelativeLayout>

これは私のコードであり、エラーが見つかりません。あなたが私を助けてくれることを願っています。

前もって感謝します。

4

0 に答える 0