Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smooth animations for heavy layouts

My application uses standard android TranslateAnimation to slide the views in and out of the screen. Unfortunately the layout seems to be quite heavy: ImageView, bunch of text views and a Gallery with text and images in it. There are two views being animated - one that slides out, and another that slides in.

The problem is in the low performance of these animations, especially on the devices with the less powerful CPU. The animations do not look smooth enough.

I am thinking of removing TranslateAnimations and trying to capture the view contents in a Bitmap and move these as ImageViews.

Do you have any ideas how such tasks should be done properly and if the image moving approach will help?

P.S.

I think that I may be using animations in a wrong way. I have two views on the FrameLayout. One is visible, the other is not. Then I handle touch events and apply the TranslateAnimations to both views (on ACTION_MOVE) as the user moves the finger along the screen. So it looks like the user moves one view out of the screen while pulling another from the side of the screen. It works fine for lightweight layouts.

like image 446
basv Avatar asked Mar 25 '11 09:03

basv


2 Answers

You should enable the drawing cache on the animated Views. Look at the documentation for View.setDrawingCacheEnabled(boolean).

like image 71
Romain Guy Avatar answered Nov 05 '22 07:11

Romain Guy


Another solution would be to render your views onto 3D surfaces and animate those via OpenGL. That's how Sony do all their nifty animations as seen e.g. in their TimeScape app.

There's a blog post about it.

like image 32
Matthias Avatar answered Nov 05 '22 07:11

Matthias