I want to add fadeout animation for my splash screen, that is while closing the splash screen I want to bring the fadeout animation effect.
Here are the codes which I have tried.
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
But the above can be used only from 2.0. Ny app should support from 1.5.
So I have set the following animation for my main activity.
getWindow().setWindowAnimations(android.R.style.Animation_Toast);
OR
getWindow().setWindowAnimations(R.style.Theme_FadeIn);
My Theme.FadeIn contains
<style name="Theme.FadeIn">
<item name="android:windowNoTitle">true</item>
<item name="android:activityOpenEnterAnimation">#anim/fade_in</item>
</style>
Now I can see the fadein effect, but I can see the blackscreen.
How to get this fadein or fadeout effect without blackscreen.
You could try to make your activity translucent... take a look at the translucent theme in the sdk
#android:style/Theme.Translucent
SWDeveloper,
While it has been about a year since I have done any Android development myself, I remember running into this exact problem with my own splash screen.
Unfortunately, for releases before 2.0, I'm fairly certain that the type of transition you want is not possible between activities. That is, in 1.5/1.6, only the built in transition animations can be used between activities.
With that being said, I seem to recall that I used view transition animations within a given activity to produce the kind of effect I was looking for. In otherwords, on my splash screen activity, fading out the initial view to just a blank white view before transitioning to the next activity. The next activity would then start on a blank white view and then fade into the actual view of the activity.
If this seems like a lot of work, you could also alternatively just include your splash screen view in your initial activity and always present it first then fade it out. All within the same activity. Using this method would probably save you time and work, but would lose you some of the modularity that comes with separating out your screens into separate activities.
The animations between views can be achieved (if I remember correctly) via the ViewFlipper widget. The android docs for it can be found here:
http://developer.android.com/reference/android/widget/ViewFlipper.html
If I can get a hold of the code base of the app that I wrote, I will try to post up an example later.
Good luck!
If you're using a separate Activity for your splash screen, you can do the overridePendingTransition call that you've noted is available in Android 2+ only. You can choose to have apps that are built for 2+ do the transition and previous versions simply do the default transition:
try {
Method method = Activity.class.getMethod("overridePendingTransition", new Class[]{int.class, int.class});
method.invoke(youractivity, inanimation, outanimation);
} catch (Exception e) {
// Can't change animation, so do nothing
}
It's better to have your splash screen a part of your main Activity (see this example). When the splash screen is part of your main activity, you can simply assign the animation to the splash screen layout.
Related
I want to achieve an effect of doing an activity transition where the user can see the previous activity while the transition is happening. As far as I understand, using overridePendingTransition(enterAnim, exitAnim) can achieve this effect, but these animations must be xml files that affect the entire activity (e.g. sliding the entire activity in), but I have a navigational bar that I want to be fixed, so this solution won't work. I also can't make my activities translucent because these animations would ideally be used in the entire app.
What I realized after playing with transitions is that even if you don't specify an activity to be translucent, the Android OS will let you see the previous activity while a transition is happening (e.g. a slide animation on an activity will let you see the previous activity while the slide happens). So I tried setting an "empty transition" by using overridePendingTransition(R.id.keep, R.id.keep) where R.id.keep references an anim xml which is a fade from 1.0 alpha to 1.0 alpha, and doing a view animation in a ValueAnimator in the onCreate of the next activity. The idea is that while the activity transition happens, the OS will let you see the previous activity, and we can take advantage of this time frame of transparency by doing a ValueAnimator on the view of the next activity (after the activity transition happens, the OS won't let you see the previous activity and will show a black screen even if you set the window background colour to be transparent, but the ValueAnimator finishes before that).
The technique I used above works well on Nougat, but it seems for API 23 and below, the UI doesn't change during the empty activity transition even though a ValueAnimator is running, and the ValueAnimator can only update the UI after the activity transition finishes. I didn't really expect this behaviour, so I'm not sure how to fix it.
Admittedly my way of doing view-level animations while being able to see the previous activity is a bit hacky, does anyone know a better way of achieving the effect I want, or some insight into why my technique works on Nougat but not on API below that?
The main activity is a login page. I have included a splash screen as well. What I want is to apply animation to the splash screen. For that, I am trying to put it in a separate fragment. How can I do this?
I have created a theme and everything that is needed to implement a basic splash screen.
Most of the apps(youtube, facebook etc) don't have an animated splash screen because, all the code initialization drops a lot of frames in your app. These frame drops will be clearly visible if you try to animate the screen.
For your animations to be smooth, a frame has to be drawn every 16ms. Even if one frame is not drawn, users can see the change... what this means is, if you are jumping a ball on ur splash screens.. the easing function you apply to the animation will not work as expected.
Solution:
In your launcher activity, just have a simple ui. As minimal as possible. This will give the user a feeling that app launched quickly. Once your initializations are over, you can attach your fragment which can have the same UI as activity and then make any transition.
In practice:
Launch activity A(launcher) -> UI can be a simple white screen with your logo in the center of the screen.
Once your initialization(all the libraries that load in your Application class like firebase, ORM, analytics tools ect) is over, attach your fragment with a screen containing the same white screen and logo.
This way the user will not know transition from activity to ur fragment as the UI is same. Now you can do any kind of animation in your screen. The initialization time varies from application to application and phone to phone.
What I want to achieve is a flip animation when going from activity to activity.
I've seen a recommendation somewhere on SO, that I should use appropriate layout animation in one activity, switch to next one without any animation whatsoever and then execute the second half of the animation in the second activity.
I guess it could work, not tried it yet. But what bothers me is more general aspect - I believe it should be possible to achieve the same effect with activity transition animation, but...
Somewhere (I guess it was SO, but I can't find it now) I've read that during the activity transition animation the background should always be fully covered by the animated activities. I'm not sure why - I can see the background is always black on all my devices, and making it visible during the animation appears to be harmless.
But perhaps it is not guaranteed? Can someone confirm that requirement? Is it officially stated anywhere?
First off I am a beginner in Android development; I have been doing a lot of research into how to get the various tasks I am trying to complete. I have yet to find any similar issue to this, which is why I am asking it.
This is a multipart question.
Overview of program and problems: I have a program (for Android 2.1 and higher) that has multiple fullscreen Activities. I am required to have a different animation for transitioning to each one. So I reconfigured a couple files and made a ViewFlipper to do the transitions. Unfortunately some of these activities use a title. At the same time the transitions that I have tried applying based on the tutorials I have found online are not working as expected. The transition begins, the second screen is shown (faded) and the background is black, as the second screen nears completion of the transition the first screen reappears before disappearing again.
Question 1: Is there a way to display some layouts with a title and some without? If not then is there a way to change the transition used when startActivity is used?
Question 2: Is there some method of doing a fade transition without it flashing the original screen? I looked up the "flicker" issue but the solutions are not working for my project.
Question 3: In a similar manner to the 2nd question, the first layout shown is a loading screen, then the main screen. This happens just fine but for some reason the loading screen is shown, then slides off (as if startActivity is called) and then it fades into existence again (this time with a title which isn't supposed to be there), then switches to the main screen correctly. What might be happening here?
If you have any questions, feel free to ask.
Q1: yes it's possible, you can set the flag for each activity
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
or in xml via style:
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
Q2: yes, that should be the usual way. But to answer your question we need to see the code you're using. If you want to change the transitions of an activity (not view), you can put in it's onCreate method:
super.overridePendingTransition(R.anim.bounce, R.anim.fadeout);
to define which animation to show when the activity enters the screen. You can use the same method in onFinish().
Q3: as Q2: need to see your code.
i have a launcher activity which shows up the blank screen at the start up..i want to show up some animation using an animatd.gif...i initialize my layouts viz home etc when the oncreate of launcher is called, but how do i add some animated image until my first layout is shown..i also doubt whether android supports animated gifs or i have to do a workaround.
Animated gifs are not supported for multiple reasons like "animated .gif are memory hogs", the workaround must be an animation
https://developer.android.com/guide/topics/resources/animation-resource.html