Android Question ZoomImageView

Sergey_New

Well-Known Member
Licensed User
Longtime User
Please advise what methods should be used to change the scale of the image and center it on the screen?
 

BlueVision

Active Member
Licensed User
Longtime User
First thoughts:
Will the images be displayed in portrait or landscape mode? Depending on the format, this then requires a change of orientation on the display. Who wants to keep turning the device 90 degrees? Nobody. So you are actually forced from the outset to specify an orientation for displaying the images regardless of the orientation of the device.
The respective orientation switches automatically depending on how the device is held. It is therefore advisable to have 2 image views from the start, formatted accordingly in the Designer for the respective orientation.
The loading of the images into the correct image view and the display of this image view with the loaded image can be defined using the programme logic.
The GRAVITY parameter of the image view should be set to Fill or Centre. I would load the images with LoadBitMapSample. This would allow you to initially display the images in full format without major distortions.

ZOOMING the images is another matter. The simplest solution would perhaps be a web view, as this is inherently scalable. However, whether it makes sense to use this ‘monster’ for displaying images is somewhat questionable in my opinion...

Edit:
Forget about using webviews. It is a hard thing display images in it. What about a BBCode window?
 
Last edited:
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Thanks for the comments. I use WebView to display images like this:
B4X:
Sub openImg
    Dim name_size As String
    Dim bmp As Bitmap
    bmp.Initialize(folder, filename)
    If wV.Height-bmp.Height>(wV.Width-bmp.Width)*wV.Height/wV.Width Then
        name_size=" style='width: " & (wV.Width/GetDeviceLayoutValues.Scale) & "px"
    Else
        name_size=" style='height: " & (wV.Height/GetDeviceLayoutValues.Scale) & "px"
    End If
    wV.LoadHtml("<html><body style='margin: 0px; padding: 0px'><div align='center'><img src='" & folder & filename & "'" & name_size &"'/></div></body></html>")
    wV.Color=Colors.LightGray
End Sub
folder - this is the path to the folder created by the program.
Everything works fine, except when the length of the image is much greater than its width, when pressing the ZoomEnabled buttons, the image moves up and goes beyond the page.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Is this what you want?
Yes.
I have one wish. When after loading I move the image to the top edge of ZoomImageView1 and press +, the image is not displayed completely. I would like the image to be moved down by the required amount in this case. This is what I could not achieve in my solution in post #5.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Is this what you want?
Wow!
Thank you, I made a modified version of the view for my own projects where I wanted to add a double tap 2 zoom feature but couldn't get it to work. Now maybe I can finally implement it.
 
Upvote 0
Top