Transitions between two Android activities not behaving as expected - android

I have some transitions set up between two activities, ActivityA and ActivityB, but they don't behave as expected. The Android API is 22 (5.0 Lollipop). A slow transition between activities is used because both activities have webviews that take a few seconds for their layouts to stabilize.
ActivityA is a NativeActivity and has two methods for switching between activities that are invoked from C++ code.
class ActivityA extends NativeActivity
{
...
protected void startActivityA()
{
startActivity(getApplicationContext(), ActivityA.class);
overridePendingTransitions(R.anim.slow_fade_in, R.anim.slow_fade_out);
}
protected void startActivityB()
{
startActivity(getApplicationContext(), ActivityB.class);
overridePendingTransitions(R.anim.slow_fade_in, R.anim.slow_fade_out);
}
...
}
ActivityB is an Activity.
The res/anim/show_fade_in.xml transition is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:interpolator="#android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:factor="1.0"
android:fillAfter="true"
android:fillBefore="true" android:fillEnabled="true"
android:duration="5000" />
</set>
The res/anim/slow_fade_out.xml transition is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:interpolator="#android:anim/decelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:factor="1.0"
android:fillAfter="true"
android:fillBefore="true" android:fillEnabled="true"
android:duration="5000" />
</set>
When ActivityA.startActivityB() is invoked from C++ code, I notice two things happen:
A slow fade to light gray of ActivityA.
The sudden appearance of the stabilized ActivityB webview.
I don't understand why #2 is a sudden appearance and not a slow fade.
When ActivityA.startActivityA() is invoked from C++ code, all I see is a quick cross-fade from ActivityB to ActivityA. I don't understand why I get a quick cross-fade instead of the programmed slow fades.
Why might I not be getting the results I expect?

Related

Activity transition black screen

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

Activity Transition sliding in/out animation

I know that are some example over the internet and also here on Stackoverflow I found many examples but belive it or not, none of them supply me needs. Even I have asked a similar question few time ago and I have stuck again into this problem. Basically is the same question but in the opposite direction. I can do whatever animation I want with Activity B but the problem here is Activity A which I could animate just in few scenarios. Basically ActivityA play enter_left only in this combination:
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_on_left);
What I want to do is to animate(move) just the Activity A either on startActivity() and onBackPressed() while Activity B stay unmoved on the screen. Activity A swould allways be drawn on top(as a sliding menu, I could do this with Activity B).
I really thought that the above snippet will do the work:
Intent intent = new Intent(ActivityA.this, ActivityB.class);
startActivityForResult(intent, 500);
overridePendingTransition(R.anim.stay_still, R.anim.exit_on_left);
but this does not even play any animation, while
//this is the animation for onBackPressed()
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
overridePendingTransition(R.anim.enter_from_left, 0);
}
animates Activity A as I want but Activity B suddenly disappears from screen and I want to stay (setting (R.anim.enter_from_left, R.anim.stay_still) does nothing).
I have prepared all 5 necessary animations:
enter_from_left
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="500"
android:fromXDelta="-100%"
android:toXDelta="0%" />
</set>
exit_on_left
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="500"
android:fromXDelta="0%"
android:toXDelta="-100%" />
</set>
enter_from_right
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="500"
android:fromXDelta="100%"
android:toXDelta="0%" />
</set>
exit_on_right
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="500"
android:fromXDelta="0%"
android:toXDelta="100%" />
</set>
stay_still
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="500"
android:fromXDelta="0%"
android:toXDelta="0%" />
</set>
I have tried a lot of combinations but non of them worked. Could you please tell me if is this animation possible and if can it be done in this way?
I will post an image, to be more clear what I want to do:
So, first step: on startActivity(), ActivityA should leave the screen from the left side and while moving, the Activity B shoull allready "be there", "below it".
Then, onBackPressed() Acyivity B should "come back", entering from the left side of the screen and overlapping the ActivityB that stay unmoved.
Not sure if you tried this combination, but should work.-
startActivityForResult(intent, 500);
overridePendingTransition(R.anim.enter_from_left, R.anim.stay_still);
I could find that the next one works very nice with fragments fragmentTransaction.setCustomAnimations(R.anim.stay_still,R.anim.exit_on_left);
while overridePendingTransition(R.anim.stay_still, R.anim.exit_on_left); does not work with activity.
On the other hand the reverse,
overridePendingTransition(R.anim.enter_from_left, 0); or
fragmentTransaction.setCustomAnimations(R.anim.enter_from_left, 0);
does not work with activity neither with fragments. The most close approach that works was
transaction.setCustomAnimations(R.anim.stay_still,R.anim.exit_on_left, R.anim.enter_from_left,R.anim.exit_on_right);
If anyone has any other solution, I'm still waiting to hear it and it will be appreciated.
5 years later but there exists a solution for this.
These two functions needs be implemented in the activity which will override the default transition.
#Override
public void startActivity(Intent intent) {
super.startActivity(intent);
overridePendingTransition(R.anim.from_right_in, R.anim.from_left_out);
}
#Override
public void startActivityForResult(Intent intent, int requestCode) {
super.startActivityForResult(intent, requestCode);
overridePendingTransition(R.anim.from_right_in, R.anim.from_left_out);
}
from_right_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0" android:interpolator="#android:interpolator/accelerate_decelerate" android:duration="300"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
</set>
from_left_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="300"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />
</set>
Try this
Add animations for activity transition in/out, in intent call like
startActivity(new Intent(this,toActivity));
overridePendingTransition( R.anim.slide_in, R.anim.slide_out);
Here is animations file, add this in anim folder
slide_in.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="100%p" android:toYDelta="0%p"
android:duration="300"/>
slide_out.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_longAnimTime"
android:fromYDelta="0%p"
android:toYDelta="100%p" />
Thanks
I don't know if i really understand what you want, but if you want to create a sliding Menu, you could use this tutorial to implement it, it works just fine - It's an alternative to resolve your problem -:
http://developer.android.com/training/implementing-navigation/nav-drawer.html
But your have to use FragmentActivity instead of Activity. If you want an example, just ask for it and i will post it. Good luck.

Slide up activity

I have an activity and another activity.
I want my first activity to end when I slide up the screen. The animation should be like the activity is sliding up too. Like the notification screen.
Is that possible? I have done many Google searches before posting this question, but could not get anything.
P.S - I don't want this to be seen as a casual question since there is no code shown. I just need some point to start and I am completely baffled.
make an anim folder in res->
Make an xml file in anim folder slide_up_info.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromYDelta="100%p"
android:toYDelta="0" />
</set>
slide_down_info.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromYDelta="0%p"
android:interpolator="#android:anim/accelerate_interpolator"
android:toYDelta="100%p" />
</set>
no_change.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0%p" android:toYDelta="0" android:duration="500"/>
</set>
Now when you want to activity up then write below code
Intent intent_info = new Intent(MainActivity.this,ToActivity.class);
startActivity(intent_info);
overridePendingTransition(R.anim.slide_up_info,R.anim.no_change);
For down Activity animation
Intent intent_home=new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent_home);
overridePendingTransition(R.anim.no_change,R.anim.slide_down_info);
Animations can be introduced to Activity Launch using OverridePendingTransition. Take a look at this example where they have showed a sample code. Animation between activities
To end an activity, you can call finish() on the first activity.
The know about the slideup, you can check onFling from GestureDetector or onTouch from OnTouchListener
You can also do it this way : in your animation, override the onAnimationEnd method, and use startActivity in it to launch your new activity after the end of the animation

Black screen between two activity using animation in android

I am using Apis 's deme for slide-in and slide-out between two activity. But when I jump from one activity to another a black screen is appearing.
Slide-Left-
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator" >
<translate
android:duration="300"
android:fromXDelta="100%p"
android:toXDelta="0" />
</set>
Slide-Right-
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator" >
<translate
android:duration="300"
android:fromXDelta="-100%p"
android:toXDelta="0" />
</set>
To Jump from one activity to another:-
Button button1 = (Button) findViewById(R.id.Button01);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
startActivity(new Intent(getApplicationContext(), SecondView.class));
overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
});
Why is this black screen is appearing between two activity.
Your first xml should be like:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator" >
<translate
android:duration="300"
android:fromXDelta="0"
android:toXDelta="100%p" />
</set>
fromXDelta is the horizontal translation applied at the beginning of the animation. Setting it to "100%p" makes the first activity shift just right out of the screen at the inception of the animation, hence the blank screen.
The call to the function overridePendingTransition(int, int) should be like this:
overridePendingTransition(R.anim.slide_right, R.anim.slide_left);
The first argument determines the transition animation used by the second activity. Also the two animations can be more properly named as slide_out_to_right and slide_in_from_left, since in fact they all slide to the right.

Android fade in , fade out animation issue

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().

Categories

Resources