I tried using the following code in .java(main activity):
final ImageView diskView1 = (ImageView) findViewById(R.id.can);
diskView1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
System.out.println("Clicked.");
AnimationSet canMov;
RotateAnimation canRotate;
TranslateAnimation canTrans;
canMov = new AnimationSet(true);
canRotate = new RotateAnimation(0,1360, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f );
canRotate.setStartOffset(50);
canRotate.setDuration(20000);
canMov.addAnimation(canRotate);
canTrans = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.35f);
canTrans.setDuration(20000);
canMov.addAnimation(canTrans);
canMov.setRepeatCount(0);
canMov.setRepeatMode(Animation.REVERSE);
diskView1.setAnimation(canMov);
}
});
I am able to get the message ‘clicked’ in LogCat, but the animation after that does not respond to the click.
However, without the use of onClick(), I get the full animation of the can.
I need the animation to start only after I click the can.
What am i doing wrong?
try calling this in the UI thread.
http://developer.android.com/reference/android/app/Activity.html#runOnUiThread(java.lang.Runnable)
Where are you calling startAnimation(animatorSet) method?