I have a camera application. Whenever the device orientation is changed from portrait to landscape and vice versa, I would like to animate the ImageView to his side.
Here's my code, the animation is done only on the first set, If the event of the orientation change occures again, nothing happens.
Here's the code:
@Override
public void onSensorChanged(SensorEvent event) {
if (event.values[1]<6.5 && event.values[1]>-6.5) {
if (orientation!=1) { // Portrait
animation = new RotateAnimation(0,90,RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
animation.setFillAfter(true);
animation.setFillEnabled(true);
animation.setDuration(0);
imageView.setAnimation(animation);
}
orientation=1;
} else {
if (orientation!=0) { // Landscape
animation = new RotateAnimation(0,270,RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
animation.setFillAfter(true);
animation.setFillEnabled(true);
animation.setDuration(0);
imageView.setAnimation(animation);
}
orientation=0;
}
}
Why does it happen, how can I make sure that whenever that event occures my animation will be applied to my imageView with other rotate paramters, and not using the same angle?