I've got an ImageButton
that rotates when the phone rotates. It rotates following the device orientation. Something like:
int rotation = this.getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0: degrees = 0; break;
case Surface.ROTATION_90: degrees = 90; break;
case Surface.ROTATION_180: degrees = 180; break;
case Surface.ROTATION_270: degrees = 270; break;
}
int relative_orientation = (current_orientation + degrees) % 360;
int ui_rotation = (360 - relative_orientation) % 360;
preview.setUIRotation(ui_rotation);
and then in the ImageButton
i'm doing this:
view = findViewById(R.id.button1);
layoutParams = (RelativeLayout.LayoutParams)view.getLayoutParams();
view.setLayoutParams(layoutParams);
view.setRotation(ui_rotation);
It works but there is no animation.. So the rotation is very drastic and not smooth.. Is there a way to put an animation?
EDIT: I add the setUIRotation() method
void setUIRotation(int ui_rotation) {
if( MyDebug.LOG )
Log.d(TAG, "setUIRotation");
this.ui_rotation = ui_rotation;
}