Custom ImageView, keep state after resize

南笙酒味 提交于 2019-12-12 02:52:17

问题


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

来源:https://stackoverflow.com/questions/18786337/custom-imageview-keep-state-after-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!