Have found already some people asking the same, but the solutions didn't work for me.
I see no animation.
Calling it this way:
Intent intent = new Intent(this, MyActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
fadein.xml and fadeout.xml are in the anim folder:
fadein.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
</set>
fadeout.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="0.0" />
</set>
Using min. API 7:
manifest:
<uses-sdk android:minSdkVersion="7"/>
API 7 is also in my project.properties file:
target=android-7
What am I doing wrong?
P.D. Removing the lines with the interpolator doesn't change anything.
Already seen / tried:
overridePendingTransition doesn't work
overridePendingTransition does not work when FLAG_ACTIVITY_REORDER_TO_FRONT is used
Fade in Activity from previous Activity in Android
Fade in Activity from previous Activity in Android
Activity transition in Android
The problem was that the device, at least in the case of Samsung Galaxy, has to have animations enabled for this to work. This can be done in the settings menu.
You need to make sure that you havn't turned it off in the device using the Settings > Developer Options:
you should turn on Transition animation scale.
As you said in some Samsung devices (maybe others to) the option "All animations" in Settings->Display->Animation ha to be selected and not the default "Some animations"
The problem that might be happen to you, for animation doesn't work, it's because your current activity is different from the next activity you intent to. And instead to make the animation he destroy the current activity, and therefor the animation doesn't show, make sure that your both activity's are in the same orientation.
Related
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
I want to create a "maximizing" effect from a dialog into my full activity, so I want the opening animation to show the activity expanding from a box to full size.
The stock launcher has done this this since Jelly Bean (pressing an app shortcut will zoom into the application from that icon's location and the Recent Apps menu has done this since ICS.
Figured it out!
Bundle options = ActivityOptionsCompat.makeScaleUpAnimation(
findViewById(android.R.id.content),
findViewById(android.R.id.content).getLeft(),
findViewById(android.R.id.content).getTop(),
findViewById(android.R.id.content).getWidth(),
findViewById(android.R.id.content).getHeight()).toBundle();
startActivity(intent, options);
It only works on API 16 and above, so put a check for it and use the plain old startActivity for older versions.
Maximize from bottom left corner would be something like this.
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:duration="2000">
<scale
android:fromXScale="0"
android:toXScale="1"
android:fromYScale="0"
android:toYScale="1"
android:pivotX="0%"
android:pivotY="100%"/>
<translate android:fromYDelta="100%p"
android:toYDelta="0%p"/>
</set>
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
I've just started working with Mono for Android, and am having trouble getting a transition animation to work on my device. It works fine in the Android emulator.
The device is a HTC Sensation, with all Animations enabled.
My animation XML files are:
slide_in_right.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/accelerate_interpolator">
<translate android:fromXDelta="100%p" android:toXDelta="0%p" android:duration="200" android:startOffset="0" />
</set>
slide_out_left.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/accelerate_interpolator">
<translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="200" />
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="200" android:startOffset="0" />
</set>
The animation is called here:
Intent intent = new Intent(this, typeof(Activity2));
StartActivity(intent);
OverridePendingTransition(Resource.Animation.slide_in_right, Resource.Animation.slide_out_left);
In the emulator, this results in the first view sliding out to the left while the new view slides in from the right.
When I upload to the device and run it, there is no sliding, the first view fades out and the second just pops up in its place.
I tried commenting out the OverridePendingTransition line to see if the fade transition was working and the sliding one not, but there was no difference. So it appears that the problem is with the OverridePendingTransition rather than any individual part of the animation.
I don't have any other Android devices to test this on, so don't know if it's a particular HTC problem.
All animation is turned on in the device settings; Facebook and other apps seem to have no problem with sliding between views.
Any help would be much appreciated.
Bryan.
I've managed to solve this problem. In case anyone else is having the same issue, the solution was to add support for largeScreen and anyDensity into the manifest file:
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:resizeable="true"
android:anyDensity="true">
</supports-screens>
All animations now work fine.
It seems that all our troubles are caused by an option in Settings / Display. Namely that window animations are turned off by default.
I created some transitions between activities that are working fine in the emulator, but nothing of them can be seen on the phone (neither fade in-out nor slide). The new activity simply appears like I have not implemented any transitions. Why is that?
fadein.xml
<?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="1000" />
fadeout.xml
<?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="1.0" android:toAlpha="0.0" android:duration="1000" />
And i set in the appropriate activity
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
Make sure that animations are enabled on device. For this go to Settings->Display->Animations and select "All Animations".
Enable the transition animation
Settings -> Developer Options -> Transition Animation Scale -> 1x
Go to Settigs then developer options and check for the options that are related to animation and assure that each one of animation option is switched on