Reputation: 2605
I am adding the animation to the imageview and I would like that to stay in that animated state till the time button is pressed on button press move it to the previous state here is my code, using setFillAfter don't let it to restore and setting it to false it don't stay in the animated state
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
i=(ImageView)findViewById(R.id.imageView1);
d=(Button)findViewById(R.id.button1);
a=new AnimationSet(false);
ScaleAnimation s=new ScaleAnimation(0, 2, 0, 2);
TranslateAnimation t=new TranslateAnimation(0, 100, 0, 0);
a.addAnimation(s);
a.addAnimation(t);
a.setRepeatCount(0);
a.setDuration(500);
a.setFillAfter(false);
a.setInterpolator(new AccelerateDecelerateInterpolator()); i.clearAnimation();
d.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
i.clearAnimation();
}
});
i.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
i.startAnimation(a);
System.out.println("OnTouch called>>>>>>>>>>>");
return false;
}
});
}
Upvotes: 0
Views: 889
Reputation: 11975
Change Repeat Mode to Infinite
a.setRepeatMode(Animation.INFINITE);
and use Animation Listener so now you can start Animation and stop Animation when ever you want.For More Details. See This Details example
Upvotes: 1