6

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.

Community
  • 1
  • 1
F0RR
  • 1,590
  • 4
  • 16
  • 30

2 Answers2

2

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
  • 67,778
  • 13
  • 73
  • 54
  • Image isn't a view. It's an actual Bitmap, which is bigger than the ImageView. – F0RR Jan 07 '10 at 19:54
  • 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 Jan 07 '10 at 20:52
  • Err.... As far as I understand, image is just logically there. After you do mImageLayout.setImageBitmap(mImage); – F0RR Jan 07 '10 at 21:00
  • mImageLayout IS your layout. And it's seems to be an imageview itselft So 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 Jan 07 '10 at 21:13
  • 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 Jan 07 '10 at 21:18
  • If this is the case what's the purpose of that calculation - what you're trying to archive in the end ? – Alex Volovoy Jan 08 '10 at 15:06
  • 1
    Well, I want to solve this problem: http://stackoverflow.com/questions/2015167/rich-image-scroll-and-zooming-on-android If 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 Jan 08 '10 at 16:47
  • 1
    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 Jan 08 '10 at 17:08
  • Yeah... Looks more like voodoo than java. Still, thanks a bunch. – F0RR Jan 08 '10 at 17:45
  • 1
    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 Jan 08 '10 at 18:08
0

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.

Kshitij Aggarwal
  • 5,287
  • 5
  • 34
  • 41