简体   繁体   English

单击图像时动画不重复

[英]Animation Not Repeating on Click of Image

On Click of a Textview i am doing frame animation using following piece of code 单击Textview我正在使用以下代码进行帧动画

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

and on Click of the TextView i am starting the animation using ribinclickanimation.start(); 单击TextView我正在使用ribinclickanimation.start();

clickframeanimation is the anim file. clickframeanimation是动画文件。 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. ribinclickanimationAnimationDrawable的对象,当我点击时它第一次正常工作但是当我第二次点击时,没有任何事情可以让任何人建议我任何帮助。

* 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: 我的clickframeanimation.xml是:

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

        }
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM