本文介绍了机器人动画点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像创建简单的动画
而我想,当它是做动画,如果用户点击图片,这个图片
敬酒开始
我所做的图像开始做动画的onCreate和我做了形象的onClick做烤面包,但问题是图像就无法点击,但如果在图像的原始位置preSS敬酒是启动(onClick的它不与动画移动)

THX对您有所帮助。

这是在动画文件夹中的动画code(translate.xml)

 <?XML版本=1.0编码=UTF-8&GT?;
    <设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
      机器人:插值=@机器人:动画/ linear_interpolator>
    <翻译
        机器人:时间=1500
        机器人:fromXDelta = - 100%P
        安卓的repeatCount =0
        机器人:REPEATMODE =反向
        机器人:toXDelta =0/>    < /集>

这是Activity类

 包com.example.animatest;进口android.app.Activity;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.view.animation.Animation;
进口android.view.animation.AnimationUtils;
进口android.widget.ImageView;
进口android.widget.Toast;公共类MainActivity延伸活动{私人ImageView的image01;私人长期aefe;
私人ImageView的image1的;
私人ImageView的IMAGE2;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
    image01 =(ImageView的)findViewById(R.id.imageView1);    最终的动画animTranslate1 = AnimationUtils.loadAnimation(这一点,
            R.anim.translate);    image01.startAnimation(animTranslate1);    image01.setOnClickListener(新OnClickListener(){        @覆盖
        公共无效的onClick(查看视图){            Toast.makeText(MainActivity.this,你好,Toast.LENGTH_SHORT)
                    。显示();        }
    });}}


解决方案

添加一个动画监听到你的animTranslate1对象。

在动画听者的onAnimationFinished()方法来设置onClickListener。

  animTranslate1.setAnimationListener(新AnimationListener(){
  @覆盖
  onAnimationEnd(动画动画){
    image01.setOnClickListener(新OnClickListener(){        @覆盖
        公共无效的onClick(查看视图){            Toast.makeText(MainActivity.this,你好,Toast.LENGTH_SHORT)
                    。显示();        }
    });
  }
});

i have create simple animation for an imageand i want this image when it is doing the animation if the user click on the imagethe toast starti made the image start doing the animation onCreate and i made the image onClick to do the toast but the problem is the image it is not clickable but if press on the original position of the image the toast is start (the onClick it is not moving with the animation)

thx for your help

this is the animation code in anim folder (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>

and this is the Activity Class

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();

        }
    });

}

}
解决方案

Add an animation listener to your animTranslate1 object.

set the onClickListener in the animation listener's onAnimationFinished() method.

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();

        }
    });
  }
});

这篇关于机器人动画点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 14:34