I'm creating a game that will have a map (an image) with some features (other images) on top. So far I'm using a subclassed View and draw everything in an onDraw
method, but I'd like to keep the images as ImageView
-s, so that I can animate them (fade-in when creating, move, etc) with Android built-in methods.
So I have the following structure:
FrameLayout (match_parent)
AbsoluteLayout (match_parent)
map: ImageView
feature1: ImageView
...
Since the map is larger than a viewport, I want to apply a scale to it. While it's possible to apply the same scale to each individual image, I'd like to keep the coordinates of all the feature images relative to a canonical size of the map and apply the master scale in a single place, namely AbsoluteLayout. The problem is that when I set scaleX
and scaleY
, the child images are clipped: the only part showing is that which would be shown if the scale wasn't applied.
This is what it looks like without applied scale:
device screen
,--------------.
| @@@@@@@@@@@@ | @@@@@
| @........... | .....
| @........... | imaginary map continues
| @........... | .....
| @...big map. | .....
| @........... | .....
| @........... | .....
| @........... | .....
| @........... | .....
| @........... | .....
`--------------'
@........... .....
@........... .....
When I apply scale, I see this: the same part of map is visible, but scaled.
,--------------.
| @@@@ |
| @... |
| @... |
| @... |
| |
| |
| |
| |
| |
| |
`--------------'
And I want to achieve this:
,--------------.
| @@@@@@@@@@@@ |
| @..........@ |
| @..scaled..@ |
| @...map....@ |
| @..........@ |
| @..........@ |
| @@@@@@@@@@@@ |
| |
| |
| |
`--------------'
Ie apply scale to the containing layout, but make it draw the "overflow", not clip it.
Is there an easy way to do this?