0

私は画像の簡単なアニメーションを作成しましたが、ユーザーが画像をクリックしてトーストを開始すると、アニメーションを実行しているときにこの画像が必要ですonCreateで画像を開始し、画像をonClickでトーストを実行しましたが、問題は画像をクリックできないことですが、画像の元の位置を押すとトーストが開始されます(onClick アニメーションで移動していません)

あなたの助けをthx

これは、anim フォルダー (translate.xml) 内のアニメーション コードです。

<?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
      android:interpolator="@android:anim/linear_interpolator" >
    <translate
        android:duration="1500"
        android:fromXDelta="-100%p"
        android:repeatCount="0"
        android:repeatMode="reverse"
        android:toXDelta="0" />

    </set>

これがアクティビティクラスです

package com.example.animatest;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends Activity {

private ImageView image01;

private long aefe;
private ImageView image1;
private ImageView image2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    image01 = (ImageView) findViewById(R.id.imageView1);

    final Animation animTranslate1 = AnimationUtils.loadAnimation(this,
            R.anim.translate);

    image01.startAnimation(animTranslate1);

    image01.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {

            Toast.makeText(MainActivity.this, "hello", Toast.LENGTH_SHORT)
                    .show();

        }
    });

}

}
4

1 に答える 1

2

アニメーション リスナーを animTranslate1 オブジェクトに追加します。

アニメーション リスナーの onAnimationFinished() メソッドで onClickListener を設定します。

animTranslate1.setAnimationListener(new AnimationListener(){
  @Override
  onAnimationEnd(Animation animation){
    image01.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {

            Toast.makeText(MainActivity.this, "hello", Toast.LENGTH_SHORT)
                    .show();

        }
    });
  }
});
于 2013-02-07T00:41:08.070 に答える