Frank
Frank

Reputation: 12300

How to bring Animation to front: bringToFront and zAdjustment/Z-ordering

I have a LinearLayout with two views in it, next to each other. When a view is tapped upon, it animates to full screen. This goes fine for the view on the right, but it fails for the left view:

I am unable to animate the left view on top of the right view

Without corrupting my layout with bringToFront(). Adjusting the Z-order of my animation does not seem to work.

Not a solution: The problem is gone when I use "brintToFront()" on the left view, but this causes my layout to be completely corrupted afterwards, and there is no brintToBack() function or whatsoever. => brintToFront = not a good solution?

Adjusting the Z-order of my animation does not seem to work (does not change anything).

scaleAnimation.setZAdjustment(Animation.ZORDER_TOP);
translateAnimation.setZAdjustment(Animation.ZORDER_TOP);
AnimationSet set = new AnimationSet(true);
set.addAnimation(scaleAnimation);
set.addAnimation(translateAnimation);
set.setZAdjustment(AnimationSet.ZORDER_TOP);
myFrameLayout.startAnimation(set);

Why does Z-ordering not work as expected?

Upvotes: 2

Views: 6997

Answers (3)

Swav
Swav

Reputation: 881

This should be possible if you extend LinearLayout and override the following method:

getChildDrawingOrder (int childCount, int i)

To make sure layout uses your function you need to call setChildrenDrawingOrderEnabled(true)

See ViewGroup javadoc

Upvotes: 6

shem
shem

Reputation: 4712

For your z reordering will apply you gonna need to request a new layout on the view, but try doing it before starting your animation:

AnimationSet set = new AnimationSet(true);
// init animation ...
scaledView.bringToFront();
scaledView.requestLayout();
myFrameLayout.startAnimation(set);

Upvotes: 3

Frank
Frank

Reputation: 12300

I guess there is no good answer to this.

I am now animating everything else on the screen too, so if view 1 has to grow larger on top of view 2 than I animate view 2 also, in such a way that it looks like view 1 is growing on top of view 2, while actually view 2 is getting smaller while view 1 is getting larger.

Quite a lot of work and a bad solution, but I guess the only solution.

Upvotes: 1

Related Questions