I am creating a Camera app.
When phone is rotated , I see a default android animation of screen rotation. In camera app this animation does not look good.
How can I disable it programatically?
I am creating a Camera app.
When phone is rotated , I see a default android animation of screen rotation. In camera app this animation does not look good.
How can I disable it programatically?
Since Api level 18 you can do this:
final WindowManager.LayoutParams lp = activity.getWindow()
.getAttributes();
lp.rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
As per this Answer (from Android Framework Engineer), the screen rotation animation work is done out of scope of an Application.
So, NO, there don't seems a way to disable it.
You should force the screen orientation to portrait (or landscape) and handle rotation using accelerometer. I guess this is the only way to display a camera preview without recreating surfaces and other UI hickups. At least this is the way a default camera application handles rotation.
Then You can add custom rotation animations to your icons, relayout UI, etc.
Successfully checked on: Java - Android 9 (Pie) - Android Studio 4.1.3 - Huawei P10
For six months I could not solve this need. The problem was in the unassigned flag "FLAG_FULLSCREEN" in code.
First step MainActivity.java:
public class MainActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); */ // If the animation still is, try applying it.
setRotationAnimation();
}
private void setRotationAnimation() {
int rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
winParams.rotationAnimation = rotationAnimation;
win.setAttributes(winParams);
}
public void Button (View view) {
// Connected to android:onClick="Button" in XML.
Intent intent = new Intent(MainActivity.this, MainActivity2.class);
startActivity(intent);
}
}
Next step MainActivity2.java:
public class MainActivity2 {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
/* getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); */ // If the animation still is, try applying it.
setRotationAnimation();
}
private void setRotationAnimation() {
int rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
winParams.rotationAnimation = rotationAnimation;
win.setAttributes(winParams);
}
public void Button (View view) {
Intent intent = new Intent(MainActivity2.this, MainActivity.class);
startActivity(intent);
}
}
Next step styles.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowFullscreen">true</item>
</style>
</resources>
Simple things I understood: You must first anywhere start "setRotationAnimation()", before running activity2. When start activity2 you have to run in it "setRotationAnimation()". Works incorrectly.