I have a layout that has some horizontal scroll on top, some text box on the bottom and whatever space is left in the middle I fill it with an ImageView. In that ImageView I load a bitmap. Let’s call this ImageView the bottom one.
Now, on top of that ImageView I load dynamically another ImageView that the user can move about by dragging it. The second ImageView (top one) has a small icon in it that will be overlayed on top of my bitmap and saved. Think of it as a logo/watermark.
Both ImageViews are in a RelativeLayout, so I can move the top layout around.
Now the problem I have is that I can not get the size of the bitmap that is loaded in the bottom ImageView.
I have tried the following:
DisplayMetrics om = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(om);
tv.setText("W:" + b.getScaledWidth(om) + " H:" + b.getScaledHeight(om));
but it won’t work, b.getScaledWidth(om) returns the actual width of my bitmap and not the one on screen, which should be (in case of a landscape image) 480px, the size of the screen of the phone I am testing on.
ADDITIONAL INFO: Why I need this is because the image I show in bottom ImageView is not of the same proportions as the ImageView. So I can get the size of the ImageView but this ImageView is larger then the image itself. As I need to keep the top ImageView inside the boundaries of image that is shown in bottom ImageView I need to know the size of the image in the bottom ImageView and not the size of the bottom View itself.
Any ideas what am I doing wrong?
I did not find a way so I did it “manually”.
I extended ImageView class with my MyImageView class and in the onMeasure override I have calculated scale factor and accordingly created a Rect representing boundaries in coordinates according to my RelativeLayout, inside of which is MyImageView.
I went this way because I found a post here that referred to creating own ImageView class, can’t find a link anymore.
Anyway, after that I check top/left positioning of top ImageView and set the maximum location while moving it around in the onTouch method.