Suppose I have multiple Images that I need to put one on top of the other, some might have some kind of animation appearing and some might even be draggable.
the largest one which usually takes the whole screen would be the bottom in the Z-coordinate (let's call it the backgroundImageView ), while all of the rest appear on top of it (and on top of others).
like so:
- backgroundImageView
- imageView1 , centered.
- imageView2 , at 60%,60% of the top left corner
- ...
If I use a FrameLayout (which seems like the best solution), the backgroundImageView would have its size fit nicely, but how can I force the other layers resize themselves accordingly?
I think I need to somehow get where to put the other layers and how to set their sizes.
The easy way is to make sure all layers have the exact same size, but that could take a lot of memory and become very slow when animating or dragging views. It would be a huge waste if some of the layers have a very small content.
this is a class that displays an image with additional layers:
and how it can be used:
anim_set.xml looks like:
with the following images:
background.png:
layer0.png:
layer1.png:
the result is:
IMPORTANT in order to prevent resources from auto OS scaling when loading from different drawable-* folders you have to use Resources object obtained from LayeredImageView.getResources() method
have fun!
just extend ImageView and override its onDraw method in order to draw additional layers
this is a minimal varsion (enhanced version with animations is in the second answer):
and how its used in your Activity:
here you have 3 images:
background.png
layer0.png
layer1.png
and three above combined
and finally the captured screen from the emulator