Jono
Jono

Reputation: 18108

SurfaceView not animating

i have created a surfaceView and attached an alpha fade in and fade out animation but it doesnt seem to animate.

Here is my animation code:

fadeOut = new AlphaAnimation(1.0f, 0.0f);
        fadeOut.setInterpolator(new AccelerateInterpolator());
        fadeOut.setDuration(1000);

        fadeIn = new AlphaAnimation(0.0f, 1.0f);
        fadeIn.setInterpolator(new AccelerateDecelerateInterpolator());
        fadeIn.setDuration(1000);
animation = new AnimationSet(false); 
        animation.addAnimation(fadeIn);
        animation.addAnimation(fadeOut);

        //this.setAnimation(animation);
        animation.setRepeatCount(Animation.INFINITE);
        animation.setRepeatMode(Animation.REVERSE);

inside my onDraw method i simply call this

super.onDraw(canvas);
    this.startAnimation(animation);

Any suggestions?

Thanks

Upvotes: 0

Views: 1292

Answers (2)

robd
robd

Reputation: 9825

Android ICS (v4) added TextureView which supports animations

Because a SurfaceView’s content does not live in the application’s window, it cannot be transformed (moved, scaled, rotated) efficiently. This makes it difficult to use a SurfaceView inside a ListView or a ScrollView. SurfaceView also cannot interact properly with some features of the UI toolkit such as fading edges or View.setAlpha().

To solve these problems, Android 4.0 introduces a new widget called TextureView that relies on the hardware accelerated 2D rendering pipeline and SurfaceTexture. TextureView offers the same capabilities as SurfaceView but, unlike SurfaceView, behaves as a regular view. You can for instance use a TextureView to display an OpenGL scene or a video stream. The TextureView itself can be animated, scrolled, etc.

Upvotes: 1

Arne Stockmans
Arne Stockmans

Reputation: 825

A SurfaceView is a special kind of view. I'm not so familiar with the exact implementation of it, but what I understood is that it creates more or less a hole in your app, and renders the view outside of the normal framework. This causes that it's not possible to do things like animations on it (or at least limits it).

If you really want a fade in animation, I suggest you implement it yourself in your SurfaceView, or you consider extending from View instead of SurfaceView.

Upvotes: 1

Related Questions