动画不重复的点击图像 [英] Animation Not Repeating on Click of Image

查看:101
本文介绍了动画不重复的点击图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单击使用下面这段code进行的TextView 我在做帧动画的

  imgclickanimation.setBackgroundResource(R.anim.clickframeanimation);
ribinclickanimation =(AnimationDrawable)imgclickanimation.getBackground();
 

和点击的的TextView 我使用启动动画 ribinclickanimation.start();

clickframeanimation 的动画文件。 和 ribinclickanimation AnimationDrawable 的对象 它正常工作,第一次当我点击,但是当我点击第二次以后什么也没有发生任何人都可以建议我的任何帮助。

*的 code:*

 包com.example.tryfinal;

进口android.os.Bundle;
进口android.app.Activity;
进口android.graphics.drawable.AnimationDrawable;
进口android.util.Log;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.ImageView;
进口android.widget.ScrollView;
进口android.widget.TextView;

公共类MainActivity扩展活动实现OnClickListener
{
    TextView的imgclickanimation;
    AnimationDrawable ribinclickanimation; //,ribinanimation;
    INT持续时间= 200;
    滚动型滚动;
    @覆盖
    公共无效的onCreate(包savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);

        imgclickanimation =(TextView中)findViewById(R.id.imgclickanimation);



        imgclickanimation.setOnClickListener(本);
        imgclickanimation.setBackgroundResource(R.anim.clickframeanimation);
        ribinclickanimation =(AnimationDrawable)imgclickanimation.getBackground();
    }
    公共无效的onClick(查看arg0中)
    {
        如果(arg0.getId()== imgclickanimation.getId())
        {
            imgclickanimation.setBackgroundResource(R.anim.clickframeanimation);
            ribinclickanimation.start();

        }
    }
}
 

和我clickframeanimation.xml是:

 < XML版本=1.0编码=UTF-8&GT?;
<动画列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:单稳=真正的>
    <项目机器人:可绘制=@可绘制/ ribin3机器人:时间=200/>
    <项目机器人:可绘制=@可绘制/ ribin4机器人:时间=200/>
    <项目机器人:可绘制=@可绘制/ ribin3机器人:时间=200/>
< /动画列表>
 

解决方案

下面是更新code

 包com.example.tryfinal;

进口android.app.Activity;
进口android.graphics.drawable.AnimationDrawable;
进口android.os.Bundle;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.ScrollView;
进口android.widget.TextView;

公共类MainActivity扩展活动实现OnClickListener {

 TextView的imgclickanimation;
    AnimationDrawable ribinclickanimation; //,ribinanimation;
    INT持续时间= 200;
    滚动型滚动;
    @覆盖
    公共无效的onCreate(包savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        imgclickanimation =(TextView中)findViewById(R.id.imgclickanimation);
        imgclickanimation.setOnClickListener(本);
        imgclickanimation.setBackgroundResource(R.anim.clickframeanimation);
        ribinclickanimation =(AnimationDrawable)imgclickanimation.getBackground();
    }
    公共无效的onClick(查看arg0中)
    {
        ribinclickanimation.stop();
        如果(arg0.getId()== imgclickanimation.getId())
        {
            imgclickanimation.setBackgroundResource(R.anim.clickframeanimation); //它仍然没有工作,这条线。没有必要再设置资源。

            ribinclickanimation.start();

        }
    }

}
 

On Click of a Textview i am doing frame animation using following piece of code

imgclickanimation.setBackgroundResource(R.anim.clickframeanimation);
ribinclickanimation= (AnimationDrawable) imgclickanimation.getBackground();

and on Click of the TextView i am starting the animation using ribinclickanimation.start();

clickframeanimation is the anim file. and ribinclickanimation is the object of AnimationDrawable It works properly for the first time when i click but when i click for the second time onwards nothing happens can anyone suggest me any help.

*CODE: *

package com.example.tryfinal;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener 
{
    TextView imgclickanimation;
    AnimationDrawable ribinclickanimation;//,ribinanimation;
    int duration=200;
    ScrollView scroll;
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imgclickanimation= (TextView) findViewById(R.id.imgclickanimation);



        imgclickanimation.setOnClickListener(this);
        imgclickanimation.setBackgroundResource(R.anim.clickframeanimation);
        ribinclickanimation= (AnimationDrawable) imgclickanimation.getBackground();
    }
    public void onClick(View arg0) 
    {
        if(arg0.getId()==imgclickanimation.getId())
        {
            imgclickanimation.setBackgroundResource(R.anim.clickframeanimation);
            ribinclickanimation.start();

        }
    }
}

and my clickframeanimation.xml is:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="true">
    <item android:drawable="@drawable/ribin3" android:duration="200" />
    <item android:drawable="@drawable/ribin4" android:duration="200" />
    <item android:drawable="@drawable/ribin3" android:duration="200" />
</animation-list>

解决方案

Here is the update code

package com.example.tryfinal;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ScrollView;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

 TextView imgclickanimation;
    AnimationDrawable ribinclickanimation;//,ribinanimation;
    int duration=200;
    ScrollView scroll;
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imgclickanimation= (TextView) findViewById(R.id.imgclickanimation);
        imgclickanimation.setOnClickListener(this);
        imgclickanimation.setBackgroundResource(R.anim.clickframeanimation);
        ribinclickanimation= (AnimationDrawable) imgclickanimation.getBackground();
    }
    public void onClick(View arg0) 
    {
        ribinclickanimation.stop();
        if(arg0.getId()==imgclickanimation.getId())
        {
            imgclickanimation.setBackgroundResource(R.anim.clickframeanimation);//It will still work without this line. There is no need to set the resource again.

            ribinclickanimation.start();

        }
    }

}

这篇关于动画不重复的点击图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆