android - 单击动画上的事件 ImageView 仅在开始位置触发

标签 android animation onclick imageview

安卓:

我有一个注册了 onClickEvent 的动画 ImageView。我希望 ImageView 在屏幕上移动,然后单击 ImageView。但是当我点击移动的 imageView 时,没有任何反应。当我单击屏幕的位置时,即 imageView 开始的位置,将触发 clickEvent。所以 ImageView 的真实位置不会随着动画移动。当有人点击屏幕上移动的图像时,有人知道如何获取事件吗?

到目前为止我的代码:

public class OnePlayer extends Activity {
private ImageView imageView;
private int points;
private TextView timeTextView;
private TextView pointsTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.oneplayer);

    timeTextView = (TextView) findViewById(R.id.time);
    timeTextView.setText("01:00");

    points = 0;
    pointsTextView = (TextView) findViewById(R.id.points);
    pointsTextView.setText("0/500");

    Animation animation = new TranslateAnimation(0, 100, 0, 200);
    animation.setDuration(2000);
    animation.setRepeatCount(-1);
    animation.initialize(10, 10, 10, 10);

    imageView = new ImageView(this);
    imageView.setImageResource(R.drawable.plus10);
    imageView.setAdjustViewBounds(true);
    imageView.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    imageView.startAnimation(animation);

    imageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            v.clearAnimation();
            v.setVisibility(View.GONE);
            points += 10;
            pointsTextView.setText(points + "/500");
        }
    });


    RelativeLayout layout = (RelativeLayout) findViewById(R.id.oneplayergame);
    layout.addView(imageView);
}

最佳答案

我已经分享了我的解决方案 here .希望这会有所帮助。

关于android - 单击动画上的事件 ImageView 仅在开始位置触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3752536/

相关文章:

android - 发出 HTTP 请求时未显示 ProgressDialog

android 打开 PackageManager 作为对话框

javascript - Velocity.js 的性能非常低

javascript - 当用户滚动到页面部分时如何触发动画

javascript - 如何根据 Javascript 中的 "class"选择器检索 onclick 事件的 href 值?

android - 如何使用android获取id onclick listview

javascript - 自动将点击事件应用于每个 HTML 元素

android - 如何在不使用 File 或 file-path 的情况下获取文件系统(不仅仅是已安装的)中 APK 文件的信息?

Android数据绑定(bind)view.onTouchListener

css - 使用CSS放大图像而不调整大小