I need a ZoomImageView which is not provided by the designer.
I need it while runtime:
B4X:
Dim svIV As ZoomImageView
svIV.Initialize (Me, "showImage")
svIV.SetBitmap(b)
svIV.tag = t
sv.Panel.AddView(svIV.ImageView, 10dip, yPos, w, h)
Additional notes:
- b is a valid bitmap
- t is a valid string
- sv is a valid ScrollView
- w and h are valid dimensions
I got an error in this line...
B4X:
svIV.SetBitmap(b)
... with this log info:
B4X:
...
Error occurred on line: 91 (ZoomImageView)
java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:89)
at anywheresoftware.b4a.objects.B4XViewWrapper.SetBitmap(B4XViewWrapper.java:377)
at de.padlockblue.manager.zoomimageview._setbitmap(zoomimageview.java:136)
at java.lang.reflect.Method.invoke(Native Method)
...
If I use a normal ImageView instance, then there is no error.
I try to add now some instances of a ZoomImageView with this code (is called in my case two times):
B4X:
Activity.LoadLayout("zi_view")
ZIV.SetBitmap(b)
ZIV.tag = t
ZIV.mBase.Enabled = True
ZIV.mBase.Visible = True
ZIV.mBase.Width = w
ZIV.mBase.Height = h
sv.Panel.AddView(ZIV.ImageView, 10dip, yPos, w, h)
While trying to add the view to my ScrollView, now I get this exception:
B4X:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:5274)
at android.view.ViewGroup.addView(ViewGroup.java:5089)
at android.view.ViewGroup.addView(ViewGroup.java:5061)
at anywheresoftware.b4a.objects.PanelWrapper.AddView(PanelWrapper.java:65)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
The layout "zi_view" only contains 1 instance of a ZoomImageView and the parent there is the Activity itself.
Custom views are designed to be added with the designer. It is however very simple to create a layout file with the custom view and load it multiple times. Tip: remove the call to AutoScaleAll from the designer script. Complete example: Sub Globals Private B4XSwitch1 As B4XSwitch End...