0

I've got an activity that contains 3 layouts, they are inflated on creation of the activity and the user can switch between them with a slide in / slide out animation (using TranslateAnimation).

I've got a custom layout that manage animation when show or hide (see below). This works perfectly when I inflate a xml layout containing basics controls, you can see the previous layout moving to the left (for example) while the other is "pushing" it arriving from the right.

The issue is that my third layout contain a subclass of GLSurfaceView and have draw a frame already on creation. I add this custom GLSurfaceView using addView to the AnimatingLinearLayout. The result is that the previous layout slide to the left as excepected but the one containing the GLSurfaceView doesn't enter and move, it is just rendered behind and is discovered while the other one leave. I would expect it to slide from the right with the frame rendered.

public class AnimatingLinearLayout extends LinearLayout
{
    Context context;
    Animation inAnimation;
    Animation outAnimation;

    public AnimatingLinearLayout(Context context)
    {
        super(context);
        this.context = context;
        initAnimations();
    }

    public AnimatingLinearLayout(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        this.context = context;
        initAnimations();
    }

    public AnimatingLinearLayout(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        this.context = context;
        initAnimations();
    }

    private void initAnimations()
    {
        inAnimation = (TranslateAnimation) AnimationUtils.loadAnimation(context, R.anim.layout_in_bottom_animation);
        outAnimation = (TranslateAnimation) AnimationUtils.loadAnimation(context, R.anim.layout_out_top_animation);
    }

    public void show()
    {
        if (isVisible()) return;
        show(true);
    }

    public void show(boolean withAnimation)
    {
        if (withAnimation) this.startAnimation(inAnimation);
        this.setVisibility(View.VISIBLE);
    }

    public void hide(Animation.AnimationListener listener)
    {
        if (!isVisible()) return;
        hide(true, listener);
    }

    public void hide(boolean withAnimation, Animation.AnimationListener listener)
    {
        if (withAnimation)
        {
            outAnimation.setAnimationListener(listener);
            this.startAnimation(outAnimation);
        } else {
            this.setVisibility(View.GONE);
        }
    }

    public boolean isVisible()
    {
        return (this.getVisibility() == View.VISIBLE);
    }

    public void overrideDefaultInAnimation(int inAnimation)
    {
        this.inAnimation = (TranslateAnimation) AnimationUtils.loadAnimation(context, inAnimation);
    }

    public void overrideDefaultOutAnimation(int outAnimation)
    {
        this.outAnimation = (TranslateAnimation) AnimationUtils.loadAnimation(context, outAnimation);
    }
}

It mights be a bit confusing, if you need anymore explanation, please ask. Thanks for help.

  • From my experience with surfaceviews (and GLSurfaceView extends surfaceviews). It is a very bad idea to try and move them cause they are punching a hole from the bottom of all the windows up to the surface. And even if you do translate it, it goes all wonky. TextureView is highly recommend to fix this. I could be way off base though as I have not yet delved into the glorious world of GL. – Whitney May 23 '14 at 21:50
  • Update: forgot in my poking around that view animations had no effect on surfaceviews I found, so try another animation method. – Whitney May 27 '14 at 21:01
  • Yes you are right, I changed it to a TextureView, the animation works much better but I support only API 14 now on... – johnlamericain May 28 '14 at 12:06
  • Best case with a SurfaceView is it looks jerky, because the View part and the Surface part don't move at exactly the same time. (Background: http://source.android.com/devices/graphics/architecture.html ) – fadden Jun 06 '14 at 17:56

0 Answers0