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.