So, I finally got my Animation sorted out (thanks to all that helped!).
However, I still have the problem that the animation is only displayed AFTER the other updates to the layout are.
What I am doing is dealing out a card to a user.
The animation shows the card sliding across the table.
However, the animation itself shows after the updates to the player's hand and the cards on the table are shown.
I tried making the update a separate thread and waiting on it but then I can't update the UI directly from there.
Sending a message to the UI thread doesn't help because the separate thread then ends after sending the message and I am back where I started.
I guess I am probably doing something wrong or missing something simple.
Any help would be appreciated.
Finally got it sorted out.
I built my own animation class which implements AnimationListener.
I then use onAnimationEnd to make the changes in the so that they happen after the animation.
Related
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
So I understand that any changes to the UI need to be on the main thread for an Android application. And also, you should use other threads to do work so that the UI doesn't freeze up. But some of the work I want to do is preparing UI elements which will be shown later on. I want to get those things ready on a separate thread and then enable a button once its done - that way the user won't be able to access it until it's ready BUT they'll be able to use the main page quickly.
Exactly what operations count as changing the UI? I want to do as much preparation in the background so that the first part of the app ready can be shown ASAP while other parts are still loading.
For example, it seems like findViewById is fine, but what about creating/modifying Views, setting listeners, setId, setEnabled and so on? If I newly create a Button which hasn't been added to a parent, can I setText on it in a background thread?
I wanted to animate a button, so I used this answer:
https://stackoverflow.com/a/4852468/559525
and got it animating on the first attempt. But then when I tried to stop the animation from various places in my application, I found that it will ONLY stop the animation if I call view.clearAnimation() from inside the onClick() callback.
My first guess is this has to do with multi threading synchronize issues, but I know about the UI thread and I was pretty sure I was calling the clearAnimation() method from approved places in the main UI thread.
My other thought was that the UI needed to be invalidated or refreshed? But I tried putting this call right before doing an invalidate on my main layout and that didn't help. I know my invalidate is working properly because it works to update other button attributes like color.
Thanks for any advice!
Currently my android application shows a black screen with a loading wheel as it processes the user's request i:e as it gets content from the server. I would like to modify this screen to include an icon (image) that fades in and out continuously instead of the loading wheel. Is there any possible way to do it?
Yes, you'll use an Alpha Animation
See here
and here
and lastly here for a good tutorial on Animations with some nice code.
In order to "chain" your animations so that one starts after the other you'll use an Animation listener and start the other one from the onAnimationEnd method callback. Don't forget to put an if statement in there that checks to see if your stuff is done loading otherwise you'll end up with infinite recursion of your fade in and fade out.
I am changing the value of several RatingBars upon completion of a child activity (inside the onActivityResult() callback). My problem is that the parent activity has not finished drawing before my RatingBars value-changing code is executed, so I get some funky lag and a half-way completed "animation" before the parent layout has even been displayed.
I'm familiar with the document.ready() function in jQuery, which waits until the DOM is completely ready to commence any script therein.
Is there any way to achieve the same result with Android? In other words, I need a way to wait until an activity has completely finished drawing itself to the user's screen before some code is executed.
This might be a simple thing in Android, but I'm pretty noob. Thanks for your time and help.
-Steve
Could you simply put the code in the onResume method which will be called after the views have been set up?? (Not sure if this include getting drawn)
Another possibility is to create a handler and dispatch a method to it at the end of the onCreate method, this will get run on the UI thread but I imagine this won't get processed until the UI thread has finished the more important stuff (i.e. drawing the views)
This is largely just me putting down possible ideas, I know there is a way of achieving this I just can't remember how.