i have a button that i animating when touched. the animation is working but after the animation is compelete, i am calling setAnimation(null) to reset the button, but the button is not getting back to its default position.
here is the code:
ok_btn_id.setOnTouchListener(new OnSwipeTouchListener(BarCodeReaderActivity.this) {
public void onSwipeTop() {
}
public void onSwipeRight() {
slidefromLeftToRight(ok_btn_id);
}
public void onSwipeLeft() {
slidefromRightToLeft(ok_btn_id);
}
public void onSwipeBottom() {
}
});
public void slidefromRightToLeft(final View view)
{
TranslateAnimation animate;
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
if (view.getHeight() == 0) {
animate = new TranslateAnimation(metrics.widthPixels/2,
0, 0, 0);
} else {
animate = new TranslateAnimation(0,-viewGroup.getWidth(), 0, 0); // View for animation
}
animate.setDuration(500);
animate.setFillAfter(false);
view.startAnimation(animate);
view.postDelayed(new Runnable() {
@Override
public void run() {
view.setAnimation(null);
view.setVisibility(View.VISIBLE);
}
}, 500);
}