3

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?

Arry
  • 895
  • 1
  • 7
  • 20
  • The original title of this question is "Don't clip a scaled view", because I want to disable clipping of a scaled view (i.e. don't clip a scaled view). The new title doesn't make sense for this question. – Arry Jan 26 '18 at 17:27
  • Have you played around with [ImageView's ScaleType](https://developer.android.com/reference/android/widget/ImageView.ScaleType.html) at all? Setting those would likely achieve what you are looking for. – pushasha Jan 26 '18 at 18:17

1 Answers1

0

This answer has what I need: just set setClipChildren(false) on the outer container (the FrameLayout).

Arry
  • 895
  • 1
  • 7
  • 20