I am starting off some animations as soon as my Activity is created.
However, by the time the Activity is fully visible the animation has already half completed.
I originally had it in onCreate but have now moved in into onWindowFocusChanged and only start the activity once I know onResume has also been called (I'm setting a boolean in onResume)
Is there anyway of knowing when an Activity is fully visible? Or am I going to have to set a 1 second delay? (This seems extremely hacky and potentially still won't work on slower phones/tablets)
If your intention is to display your animations to the user, one way you could guarantee they see the entire animation is by triggering it with an onClickListener() for the whole screen, and just wait for them to touch it?
for layout animations you can use LayoutAnimation, here is the link here
As of API level 21, you can implement the Activity#onEnterAnimationComplete() callback. Unfortunately, it seems like there's no AppCompat equivalent at this point.
Related
I just wrote a simple custom Transition, that animates elevation.
However if I run the transition again via TransitionManager.beginDelayedTransition during the previous one already running, I do observe the previous animator still running, i.e. they both are running at the same time. Visually its not a problem since the second transition always seems to overwrite the value set but the previous animator.
But' this for sure can break in some more complex scenario, so I'd best like to cancel the previous transition animators before starting the new.
Is there an api for that? I see there is protected cancel() but I don't see any of its usage. Also, I've looked at the stock transitions like ChangeBounds and also they don't seem to care
From Activity lifecycle we know, that in onResume the UI is visible. But if I set a breakpoint on onResume, I still don't see it, only after that. I heard there's some method which can check it, but I can't remind how it calls. We used it to make better animation. So how can I be fully sured that UI is ready?
Add global layout listener on view you want to check. Also please make sure that you remove listener once your work is done else it will keep getting called multiple times.
#onik shared a good link that should solve your problem
This ensures lay-outing. Drawing happens continuously and frame are refreshed according to sys clock.
I recommend watching: https://www.youtube.com/watch?v=Q8m9sHdyXnE
This will give you good idea on android drawing and layouting
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?
A very odd issue that I'm not able to diagnose or figure out, so I'm hoping that someone else has seen this and might have a clue as to what's going on.
All Activities inherit from AppCompatActivity.
The scenario is as this:
Activity 1 (extends AppCompatActivity) starts Activity 2
Activity 2 performs some action after user input and then exits via onBackPressed
Activity 1 displays a Snackbar based on the action performed with Activity 2 as a means of confirmation
The problem is that the Snackbar doesn't show at all or is delayed and flickers on as it is dismissing. If I touch the screen and interact with Activity 1, the Snackbar becomes immediately visible.
I also turned on "Show layout boundaries" via the Developer Options and I can see that the Snackbar isn't actually being displayed (invisible) until I touch the screen (or until it starts to animate out).
I created a sample application and it seems to be working fine there, but no such luck in our production application. Activity 1 itself is displaying a lot of information and content in a ScrollView, but I wouldn't think that this would cause an issue, unless there are rendering passes that are happening that I can't tell and that is causing the delay in display.
I've created a project that you can use to demonstrate this problem. I believe that this is a bug, and you can work around it by not using your own transitions. Though I also believe that not all transition animations will cause the issue. I think the hold animation in this case is the culprit.
Here is a brief outline of the issue:
Activity 1 and 2 both have Scroll Views with a bunch of content.
Activity 2 opens Activity 2 using overridePendingTransition( slide_up, slide_down), though this isn't necessary for this example.
Activity 3 displays content and then is closed:
a) using overridePendingTransition( hold, slide_down ). In order to see the Snackbar in this scenario, you will need to touch the screen and interact with Activity 1.
b) using no Transition. The Snackbar should be visible.
My solution to this issue was to remove overridePendingTransition. Please comment if you have additional ideas about this.
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?