tags:

views:

187

answers:

2

So here's the problem. I am displaying a big image in ImageView and need to find it's position relative to the image. Like this:

╔═══════════════════════════════╗
║ Image                         ║ 
║──>╔═════════════╗             ║
║   ║ ImageView   ║             ║
║   ║             ║             ║
║   ╚═════════════╝             ║
║                               ║
║                               ║
╚═══════════════════════════════╝

Any help?

UPD: Since there were some misunderstandings I will explain the problem in detail.

I have an image. A Bitmap actually. I am displaying it in an ImageView with CENTER scale type. Assume that the image is bigger than the ImageView, so only a part of the image is displayed. I want to find the position of this part relative to the whole image.

+1  A: 

getTop() , getLeft() on the child view won't solve it ? And if views are not parent-child , but have same parent - do it for each view and do the math

Alex Volovoy
Image isn't a view. It's an actual Bitmap, which is bigger than the ImageView.
F0RR
But your bitmap does resides in some sort of layout right ? If you there is a frame layout where both of those are resided than getLeft() on imageview - padding you use for the Image should give you the x right ?
Alex Volovoy
Err.... As far as I understand, image is just logically there. After you domImageLayout.setImageBitmap(mImage);
F0RR
mImageLayout IS your layout. And it's seems to be an imageview itselftSo who the parent of the mImageLayout and ImageView ? If it's the same - just do mImageLayout.getLeft imageView.getLeft() and do the math
Alex Volovoy
The way you drawn that - it's two image views inside RelativeLayout. One of them mImageLayout just happen to be set bitmap from code.
Alex Volovoy
I updated the question to clear the misunderstanding.
F0RR
If this is the case what's the purpose of that calculation - what you're trying to archive in the end ?
Alex Volovoy
Well, I want to solve this problem: http://stackoverflow.com/questions/2015167/rich-image-scroll-and-zooming-on-androidIf I can find out / calculate realtive position of ImageView, then I can implement scrolling with scrollBy/scrollTo. Without it I can't tell, whether the image is leaving ImageView bounds.
F0RR
Ah.. Yeah i'm not sure how to deal with that. I'd try to get rid of the scale type on the image view. Pre scale a bitmap myself by createScaledBitmap(src, dstWidth, dstHeight, filter) or createBitmap(params) - that way you know where you at relatively from original. Not sure if it's a right or efficient approach
Alex Volovoy
Yeah... Looks more like voodoo than java. Still, thanks a bunch.
F0RR
Not really a voodoo - if the goal to know relative x. If you prescale bitmap yourself by specifying start x,y from the source - mission accomplished. If you ask somebody else do it for you ( OS ) than you have to try to figure out those values - so i'd say take control from beginning.
Alex Volovoy
Yep. Still it somehow fills like a should-be prebuilt feature...
F0RR
A: 

The image render starts from the top-left corner of the image so even if the image is bigger then the imageview, you will always see the top-left corner.

Funkyidol