I am working on some Android animation effects. On one screen there are several background images fading in/out constantly, and there is also a text marquee. The problem is that the text marquee is kind of choppy. When the image fade in/out is disabled, the marquee is smooth, so it is likely the 2 animations are affecting each other.
I am wondering if there is a way out other than writing my own animation by using Canvas or SurfaceView.
I took a look at AnimationSet, but that is only good for combining animations for the same view.
It has been a while but here are the things I have found along the way:
To achieve smooth text scrolling animation, it needs about 50 frames per second. So it really stretches the CPU out. I tried to use a surfaceView to do both the image and text animation, and managed to get to 35 frames per second but that was not enough, the text scrolling is still a little jumpy. I read a little opengl and it looks like OpenGL ES 2.0 should be able to handle the image fade in/out in parallel ways. But did not really go through with it. Hope this helps.
Related
I am implementing a piano tiles clone for an educational purposes. I've created 5 Views (that's the rows) which extends LinearLayout. Each one of them has 4 childs (that's the 4 tiles).
I am using an Handler for the animation, and change the Y property manually every "tick".
Problem is, the animation is somewhat twitching and not smooth.
I have two questions:
Is that a good design? I know for example about surfaceView as alternative for drawing and animating but that seemed to me a bit complicated for my cause.
How would you animate those tiles? currently I use an Handler (actually I was guided on another thread to use Animation. What do you think the most feet to my case?
Thanks!
I like your grid idea, but you may have to change it if you would like the tiles to be procedurally generated. Also, here is a thread on how to make animations smoother in Java (This can probably apply to Android too):
How can I make a Java Swing animation smoother
Here is one for Android: Moving animation not smooth in android
Also, I feel you are a bit behind, the Piano Tiles phase has disappeared now, much like Flappy bird.
I'm experiencing the following problem with animations in Android: I want to animate some boats moving from right to left in and out of the screen. These boats have text written on them and these texts have to move along with the boats. What I implemented is a layout with 4 boats and animate them 1 length to the left with a translate animation and then repeat this animation. The boat in the center has a certain text written on it and the boat to the right has the second text, so the user can see it as the boat moves into the screen. However, when the animation repeats itself, the text from the right boat is drawn on the new center boat, which causes a flickering effect while the boat animation looks fine. Please see the video for an example. This video was recorded from the emulator and it exaggerates the problem a bit, on actual devices it's more of a flickering effect.
I've tried several possible solutions found on SO, such as .setFillAfter(true) and delaying the drawing of the next repetition, but none of this solves the problem. Does anyone know a solution to this problem?
We are trying to create a text animation like Transition and Zoom on the Video.
We are not able to get Smooth transition and the effect is so jerky. Then we understood sub pixel rendering is not possible in android.
What alternatives can we think of? Can we solve this problem in OpenGL?
Ok... I would like to add more to my question....We are actually trying to implement text animations on top of a video which is played by a native player on a surface view.
We tried to achieve the text animations using the android Canvas APIs to scale, translate etc and draw the text. This works but the output is not so smooth. We have verified that its not a performance issue. Even if we refresh the frames at more than 30fps, the
jerkiness is seen.
Then, we tried to use android Views to get these animations and observed that the animations are buttery smooth when Hardware acceleration is turned on. But even the android View system animation fails to give good quality scale animations when hardware acceleration is turned OFF.
This again is not a performance issue since we have tried to dump each frame into a bitmap and checked each frame on PC.
So, it seems that SKIA graphics library used to draw on Canvas when hardware acceleration is turned off, is not capable of sub pixel rendering or something of that sort. For example, when i am running a slow scale animation (a scale of about 0.15 in about 6 seconds), the scale updates happen by 1 pixel in around 3 frames.
But if the same animation is run on a hardware accelerated view, each frames updates a fraction of a pixel and the scale animation looks
very smooth.
I can sure use the view animations while previewing. But I need to get these animation buffers and encode them along with the video. Any inputs on getting these buffers, with hardware acceleration turned ON would help. I have tried Drawing cache, but that seems to be drawn using software rendering pipeline and not hardware.
Smooth transistions and jerky animations have nothing to do with subpixel rendering.
The problem sounds like you're not correctly timing your rendering function. Do not use a interval timer to trigger rendering of a frame. You should put the rendering and animation into your programs event loop idle handler and measure the time it takes to render a frame. Then advance the animation by that time.
I currently have an app with a regular layout of buttons and widgets. On top of this I'd like to draw some animated sparks and particles and whatnot going on in response to events, so I've got it in a FrameLayout with another View on top to draw the animations. The problem is I can't work out a way of getting smooth movement out of it. I've tried a few options:
SurfaceView: because of the way it takes over the screen, you can't see anything behind a SurfaceView so the background is fully black.
Override View.onDraw and call invalidate(): this almost works, but invalidate isn't a very reliable way of getting a redraw to happen soon, so the motion is very jerky.
Animation framework: Testing with TranslateAnimation, it seems a bit smoother than using onDraw(), but animations are designed to run for a specific duration and I want to draw indefinitely.
Anybody know any tricks to make one of these work properly, or something completely different?
I'm working on a game that in some ways is similar to Tetris (imagine a 2D array of colored squares that sometimes move around)
I am trying to animate the individual squares so they will smoothly slide down from coordinate to the next. Since I wanted to use Android's built-in tweening feature, the animation has to apply to the whole View (rather than parts of it). This doesn't work well for me because I only want some of the colored squares to slide down, and the rest of them to stay still.
The (theoretical) solution I came up with to resolve this is to make 2 Views, layered directly on top of each other. The top view is for animating squares when they need to move, and the bottom layer is for the static squares. The animation-layer is transparent until I am ready to animate something. I then simply turn on the colored square in the animation-layer, tween it to the new location, and turn it back off when done. In the same time span, the static-layer just turns squares on and off at the right time to make the whole thing look seamless to the end user.
The proposed solution is just a theory, since I haven't been able to make it work correctly yet. Since I have been having trouble, I was wondering if this is even the best way to solve the problem? Perhaps there is a more elegant solution that I am over looking? Anyone know of a better way?
If you just want to animate a single element check out the namespace android.view.animation.Animation. You can also use Drawable shapes and draw them directly. Finally, if you want a simulation then you will have to look into threading. Basically you will create a timer to update the canvas for you based on an interval. There are some other view canvases you can use as well like the GLView canvas.