First of all I'm working with the Android-L preview. Now, For anyone to not to misunderstand what navigation bar is, here's a pic of it:
https://imageshack.com/i/f0bjjDnQp
I'm applying the activity animation that follows:
activity.startActivity(intent);
activity.overridePendingTransition(R.anim.slide_in_from_bottom, R.anim.scale_in);
Where R.anim.slide_in_from_bottom.xml is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="100%"
android:toYDelta="0%"/>
</set>
and R.anim.scale_in is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="300"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.9"
android:toYScale="0.9"/>
<alpha
android:duration="300"
android:fromAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="0.1"/>
</set>
The animation works fine except for the fact that the new activity does the animation on top of the navigation bar, I'd like it to be the opposite. Also I can see the black status bar during the whole animation which I would like to avoid too.
UPDATE:
So I found what the problem is. With the introduction of Android L preview we have the option to set this Material theme, and that theme makes the animations between activities this way. If I set android:Theme.Holo.Light for instance, everything works fine. As soon as I add this Material theme I got this ugly effect of overlaying the Navigation Bar.
So I thought I could try to find the right parameter in the Material Theme to make it behave as the old theme but I can't manage to figure it out. I've tried setting this line below, but it doesn't work either.
<item name="android:windowActionBarOverlay" >false</item>
Related
Does anybody has an example of animation that looks like tilting slightly on left and right but middle is not moving. It looks like when you want to move icons on iOS and make a long press you could see that kind of animation what I need. I got animation but it more looks like moving the whole item instead of tilting. Here is my code
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="70"
android:interpolator="#android:anim/linear_interpolator"
android:pivotX="40%"
android:pivotY="40%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toDegrees="1" />
<translate
android:duration="70"
android:fromXDelta="-3"
android:fromYDelta="3"
android:interpolator="#android:anim/linear_interpolator"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toXDelta="0.1" />
</set>
Its like wiggling effect on this screen
The rotation effect can be made by adding 2 parameters
android:fromDegrees="0"
android:toDegrees="3"
So I've got WelcomeActivity -> HomeActivity and closing WelcomeActivity with finish()/supportFinishAfterTransition(). I want to do either a slideTransition or a fadeTransition (open to other suggestions btw).
I've researched this and as it turns out there are 2+ ways of doing it: either with overridePendingTransition which uses anim.xml files or with Transitions (from the android docs) which use transition.xml files...
I've tried both and both give me unwanted results:
for anims: I get this ugly mid transition black screen:
fade_in.xml:
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="300" />
fade_out.xml:
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:zAdjustment="top"
android:duration="300" />
WelcomeActivity: (I've tried having finish before the overridePendingTransaction)
startActivity(Intent(this, HomeActivity::class.java))
overridePendingTransition(R.anim.fade_in, R.anim.fade_out)
finish()
for transitions: I can't make it so WelcomeActivity closes properly: It either closes before the animation starts or not closing at all. I'm following the android docs.. I've also tried this:
style.xml
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowEnterTransition">#transition/enter_fade</item>
<item name="android:windowExitTransition">#transition/exit_fade</item>
My other questions is which approach should I have? Is Google pushing the transitions over the anims for starting new activities?
What I always do is to start an activity(any way you want, ways are listed here).
I use slide transitions using these two files:
slide_out_left.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="#android:integer/config_mediumAnimTime"
android:fromXDelta="0"
android:toXDelta="-100%p" />
</set>
slide_in_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="#android:integer/config_mediumAnimTime"
android:fromXDelta="100%p"
android:toXDelta="0" />
</set>
Then I start an activity like this(this is java):
startActivity(MainActivity.this, SecondActivity.class);
overridePendingTransition(R.anim.slide_in_right.xml, R.anim.slide_in_left.xml);
finish();
Using this, the activity exits giving way to the new one smoothly from right to left.
For the black screen, set the theme of that activity as translucent in the AndroidManifest.xml file
android:theme="#android:style/Theme.Translucent"
so your code will be something like this
<activity android:name=".Activity"
android:theme="#android:style/Theme.Translucent" />
Answer for the black screen taken from: https://stackoverflow.com/a/6468734/9819031
Fragment animations do not work properly with support-v4:27.1.0
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(ENTER_ANIM , LEAVE_ANIM)
.replace(R.id.main_activity_fragment_place_holder, fragment)
.addToBackStack(tag)
.commitAllowingStateLoss();
enter animation
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="500" />
leave animation
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="500" />
I just hit the same problem. Support library 27.1.0 seems to have a problem with anim transitions that use the alpha property.
My impression is that the transition engine does not correctly implement a "fill-after", so that the fragment alpha quickly bounces back to 1 before the fragment is removed. This causes a blinking effect where the replaced fragment is briefly visible and then disappears.
I resolved the issue switching to animator transitions.
I.e. replaced my /res/anim/fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0"
android:toAlpha="1"
android:duration="500"
/>
with an analogous /res/animator/fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="alpha"
android:valueFrom="0"
android:valueTo="1"
android:duration="500"
/>
I did the same for the fade_out transition.
The blinking effect was fixed in the latest support library version 27.1.1. (see issue 74051124)
I have the exact same problem after upgrading the support library from 27.0.2 to 27.1.0. Instead of fading smoothly, the fragments blink several times.
It seems that all animators work as expected, except alpha animators.
However, I have found a workaround for this bug: If you disable the enter animation, the transition still fades. It does not fade in the exact same way as before, but it looks good (or even better) in my opinion.
The new enter animation (which I have named nothing.xml) is:
<?xml version="1.0" encoding="utf-8"?>
<set/>
I have to animate a drawer icon. The red circle needs to pop up in the same way as in the gif below. Any of the animation styles are fine, I only want to know if I can create an animation like these. Any thoughts?
I have searched the internet, but I haven't found anything so far.
You could try using the scale animation, for example, to get a similar effect of the pop animation in that gif you could do the following:
Create a file res/anim/bounce.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/bounce_interpolator">
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="800"
android:fromXScale="1.5"
android:fromYScale="1.5"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1"
android:toYScale="1" />
</set>
And then load the animation:
Animation bounceAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.bounce);
yourView.startAnimation(bounceAnimation);
I'm trying to customize the animation between two activities by fading out the splashscreen and fading in the main activity.
I trying two solutions, one with fade_in.xml and fade_out.xml where controlling alphas (0-1 , 1-0) and calling everything with overridePendingTransaction(fade_in, fade_out) and one with fade and hold like ni api demo (api/app/animation/fade);
The main problem is that the splashscreen (first animation ) is losing its alpha while sliding to the right as well and the second activity is appearing as wanted.
How is possible to lock the splashscreen to its original position and just making it fading out?
fade
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="#android:integer/config_longAnimTime" />
hold
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:fromXDelta="0" android:toXDelta="0"
android:duration="#android:integer/config_longAnimTime" />
overridePendingTransition(R.anim.fade, R.anim.hold);
You can use the callback for .fadeOut().