0

I implemented a Custom ImageView based on Nicolas Tyler's post here: https://stackoverflow.com/a/17649895/680488

It works really good but I have one problem:

I have the custom ImageView inside a layout with one other layout below the ImageView. This second layout's visibility can be toggled by the user. Whenever this happens, the ImageView gets resized (to fill the whole activity or make space for the other layout). So far so good. The problem is, that when this re-sizing occurs, the ImageView seems to 'lose' its imagematrix and the image is shown again in its original state (zoomed out, so that the whole image fits on the screen).

I want to keep the last state before the re-sizing (scroll/zoom back to the same position (or just stay there)). So the question is, when is the best situation to store the imageview's matrix and when to apply it again? (onSizeChanged seems to be to late, right?)

I hope it's clear enough...?

EDIT: after I implemented it as described in the comments I now have really weird behavior: It first looks good, and the imageView stays at (or actually goes back to) the same state as it was before the visibility change of the other view. However, when I then touch the view to scroll or zoom, it moves a couple of pixels and then jumps to a completely different position and the controls don't work anymore (I cant scroll/zoom). I printed out the matrix values while touching after resizing:

OnTouch: 1.204599, 0.0, -1254.761, 0.0, 1.204599, -107.23739, 0.0, 0.0, 1.0
OnTouch: 1.204599, 0.0, -1254.761, 0.0, 1.204599, -107.23739, 0.0, 0.0, 1.0
OnTouch: 1.204599, 0.0, -1254.761, 0.0, 1.204599, -107.23739, 0.0, 0.0, 1.0
OnTouch: 1.204599, 0.0, -1254.761, 0.0, 1.204599, -107.23739, 0.0, 0.0, 1.0
OnTouch: 1.204599, 0.0, -1254.761, 0.0, 1.204599, -107.23739, 0.0, 0.0, 1.0
OnTouch: 1.204599, 0.0, -1254.761, 0.0, 1.204599, -107.23739, 0.0, 0.0, 1.0
OnTouch: 1.204599, 0.0, 0.0, 0.0, 1.204599, -107.23739, 0.0, 0.0, 1.0
OnTouch: 1.204599, 0.0, 0.0, 0.0, 1.204599, -107.23739, 0.0, 0.0, 1.0
OnTouch: 1.204599, 0.0, 0.0, 0.0, 1.204599, -107.23739, 0.0, 0.0, 1.0
OnTouch: 1.204599, 0.0, 0.0, 0.0, 1.204599, -107.23739, 0.0, 0.0, 1.0
OnTouch: 1.204599, 0.0, 0.0, 0.0, 1.204599, -107.23739, 0.0, 0.0, 1.0
OnTouch: 1.204599, 0.0, 0.0, 0.0, 1.204599, -107.23739, 0.0, 0.0, 1.0

so TRANS_X is at once jumping to zero. Any ideas why something like this could happen?

Cheers, J

Community
  • 1
  • 1
jpm
  • 3,300
  • 1
  • 19
  • 29
  • 1
    have you tried putting the other view in a separate view from the ImageView? You could try storing the matrix value when the visibility is toggled and then just reapply it after a second. – string.Empty Sep 13 '13 at 12:54
  • Thanks! I don't know why I didn't have the idea of handling it outside the view... I now store the matrix before I set the other view's visibility and then reapply it in the imageview's onSizeChanged(). (If I reapply it right after the new visibility was set, the matrix is reset at some later point). Thanks again! – jpm Sep 13 '13 at 13:42
  • mhh wasn't as successful as I thought...see EDIT – jpm Sep 13 '13 at 14:41
  • could you show us your xml? – string.Empty Sep 13 '13 at 15:44
  • ok, i'm pretty sure, it's very app/view specific. It has something to do with some of the values that are not set after the new matrix and the view's new size were applied...I guess I'll figure it out somehow, but I don't think it will help anybody else. So I'll close this thread (or at least I'm trying...) – jpm Sep 13 '13 at 15:46

0 Answers0