B4A Library ZoomControls

warwound

Expert
Licensed User
This small n simple library wraps the android ZoomControls class:
http://developer.android.com/reference/android/widget/ZoomControls.html

It provides the 'traditional' zoom controls as seen in the attached screengrab.

ZoomControls
Version: 1.10
  • ZoomControls
    Events:
    • ZoomInClick
    • ZoomOutClick
    Methods:
    • HasFocus As Boolean
      Returns true if this view has or contains focus.
    • Hide
    • Initialize (EventName As String)
    • Show
    Properties:
    • ZoomInEnabled As Boolean [write only]
    • ZoomOutEnabled As Boolean [write only]
    • ZoomSpeed As Long [write only]
      Sets how fast you get zoom events when the user holds down the zoom in or zoom out buttons.
      Default is 1000ms.

ZoomControls is a standard android View so also has all the other standard View methods and properties.
Usage is simple:

B4X:
Sub Process_Globals
End Sub

Sub Globals
	Dim ZoomControls1 As ZoomControls
End Sub

Sub Activity_Create(FirstTime As Boolean)
	ZoomControls1.Initialize("ZoomControls1")
	
	'	using -2 for width and height which is android WRAP_CONTENT constant
	Activity.AddView(ZoomControls1, 0, 0, -2, -2)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub ZoomControls1_ZoomInClick
	ToastMessageShow("Zoom IN", False)
End Sub

Sub ZoomControls1_ZoomOutClick
	ToastMessageShow("Zoom OUT", False)
End Sub
Using the android WRAP_CONTENT constant makes the ZoomControls adjust it's size to fit it's 'native' dimensions.
The ZoomControls will not expand if you set a width or height larger than it's native width or height.
But it will clip/shrink in size if you set a smaller than native width or height.
Experiment with the above code and that'll all make sense:

B4X:
'	the ZoomControls doesn't expand to 200x150
Activity.AddView(ZoomControls1, 0, 0, 200dip, 150dip)
B4X:
'	the ZoomControls shrinks/clips to 96x32
Activity.AddView(ZoomControls1, 0, 0, 96dip, 32dip)
I haven't yet established what the ZoomControls actual native dimensions are - be sure to post those dimensions if you can find them.

Library files and demo project attached.

Martin.
 

Attachments

Last edited:

warwound

Expert
Licensed User
I've just updated ZoomControls to version 1.10.
This update adds the new property:

ZoomSpeed As Long [write only]
Sets how fast you get zoom events when the user holds down the zoom in or zoom out buttons.
Default is 1000ms.


Version 1.10 attached to post #1 in this thread.
 

Mahares

Well Known Member
Licensed User
Version 1.10 attached to post #1 in this thread.
I have been trying to figure out what this library is supposed to do, but have no idea. All I see is the zoom control on the screen in Warwound's example. Are you supposed to expand, zoom in, zoom out views or what. Can someone please explain how this library can be used, perhaps with a simple code.
Thank you
 
Top