2

I am trying to add ImageButton's in my Android Application from a list imgBtns to an already existing ImageView in this way:

for (int k = 0; k < imgBtns.size(); k++) {
    zoomLayout.addView(imgBtns.get(k));
}

The ImageView is zoomable via an ImageMatrix that adjusts according to the finger gestures.

My Problem is, that when I add the ImageButton, the ImageMatrix of the ImageView somehow resets and I end up looking at the fully zoomed out image! I tried assigning the matrix manually after the adding and I played with the LayoutParams, but it always resets the ImageMatrix!

Does someone have an idea why this happens and how I can add my ImageButton's to the zoomed-in ImageView so that it stays zoomed-in?

EDIT:

It turns out the ImageMatrix doesn't get reseted, but something else instead. My guess is, that adding a View to the Layout somehow resets the Layout and its children. I don't know what exactly is going on, but I think changing the Layout after the onCreate() has some complicated consequences...

Clemens
  • 21
  • 5
  • what is `scaleType` of `imgBtns.get(k)` when you call `addView`? – pskink Dec 31 '16 at 07:12
  • @pskink: I've tried initializing the 'ImageButton' 's with 'ImageView.ScaleType.MATRIX' and 'ImageView.ScaleType.CENTER' , but it doesn't seem to make a difference... – Clemens Dec 31 '16 at 09:13
  • does it have to be an `ImageButton`? why not a custom `View` where you have the full control of what is drawn? – pskink Dec 31 '16 at 09:17
  • you're right, it doesn't have to be a `ImageButton` for my purpose. So I just tried it with a `View`, but Views don't have the `setMaxHeigth() setMaxWidth()` functions, so I think I can't set their size so easily. I then tried using a `ImageView`, but again the same problem occurs like when using `ImageButton` 's: no zooming possible anymore... – Clemens Dec 31 '16 at 11:02
  • what actually do you want to achieve? – pskink Dec 31 '16 at 11:05
  • so far I have these `ImageButton`'s on a picture (the zoomable `ImageView`) on certain positions. Now all I want to achieve is that when I zoom into the picture, that only the still visible buttons (with their position within the zoomed-in region) are visible.
    The problem is, I have to delete all the `ImageButton`'s as soon as I touch the screen to zoom/slide, because otherwise the buttons are in the way of the gesture detection. Therefore I have to redraw them after the zooming/sliding on a new position.
    – Clemens Dec 31 '16 at 11:30
  • cannot you simply draw the bitmaps using the matrix? – pskink Dec 31 '16 at 12:24

0 Answers0