Java Question ScrollView replace Panel

warwound

Expert
Licensed User
Longtime User
I've wrapped an android java View into a library and want to set this library View as the ScrollView Panel.
This is my new library:

B4X:
public class ZoomPanel extends PanelWrapper {

   /**
    * ZoomPanel is an enhanced Panel that supports pinch-zoom and drag.
    */
   public static void LIBRARY_DOC(){}
   
   @Override
   public void Initialize(BA pBA, String EventName) {
     super.Initialize(pBA, EventName);
   }

   @Hide
   @Override
   public void innerInitialize(BA pBA, String pEventName, boolean pKeepOldObject) {
     if(!pKeepOldObject){
       setObject(new pl.polidea.view.ZoomView(pBA.context));
       //   TODO add listener?
     }
     super.innerInitialize(pBA, pEventName, true);
   }
}

You can find the source for the wrapped class (pl.polidea.view.ZoomView) here: http://code.google.com/p/android-zoom-view/source/browse/src/pl/polidea/view/ZoomView.java.
The wrapped class extends the FrameLayout class, as FrameLayout extends ViewGroup and a B4A Panel is a ViewGroup i was hoping that anywhere a B4A Panel is used, my ZoomPanel could be used as a direct replacement.

My aim is to add pinch-zoom and drag to a TableView.
I suspect it won't work - the ScrollView will receive all touch events and my ZoomPanel will not.
But i wanted to test it anyway and thought it's be easiest to pass a ScrollView to a library method where the ScrollView first (and only) child View is replaced with my ZoomPanel, so added this method to my library:

B4X:
   public void ReplacePanelWithZoomPanel(ScrollView ScrollView1){
     ScrollView1.addView(getObject(), 0);
   }

An exception is raised - the ScrollView already has a child View, my method seems to be trying to insert the ZoomPanel at index 0 instead of replacing the existing Panel with the ZoomPanel.
So i've been looking at the Panel source in core.jar using jd-gui and cannot see where the ScrollView's one and only child View is created.
A B4A ScrollView wraps the MyScrollView class.
MyScrollView extends ScrollView.
No where do i see where the ScrollView (or MyScrollView) child is created.
All examples on the web that show programmatically creating a ScrollView show the ScrollView's only child View also being created programmatically.
This does not create a ScrollView with a child View, it creates a ScrollView with no child (i think):

B4X:
ScrollView myScrollView = new ScrollView(aContext);

So i'm asking can i replace the Panel in a ScrollView with my ZoomPanel and if so, what java syntax would i use.

Thanks.

Martin.
 

thedesolatesoul

Expert
Licensed User
Longtime User
So i've been looking at the Panel source in core.jar using jd-gui and cannot see where the ScrollView's one and only child View is created.
A B4A ScrollView wraps the MyScrollView class.
MyScrollView extends ScrollView.
No where do i see where the ScrollView (or MyScrollView) child is created.
The panel is added in Initialize2 method of ScrollViewWrapper. This is the actual scrollview created in B4A.

Secondly, can you not remove all views from the scrollview and then add your view?
 

warwound

Expert
Licensed User
Longtime User
Thanks for the help.

As you said the Panel is created in Initialize2 method of the ScrollView.
So i added some java to my library method to removeAllViews on the ScrollView then add my ZoomPanel as the ScrollView's only child.

Now I got exceptions where the ZoomPanel's FrameLayoutParams couldn't be cast to BALayoutParams.
So i modified the ZoomPanel to extend BALayout instead of FrameLayout.

No exceptions now.
Only the first column in the first row of the table displays.
Pinch zoom causes that single row/column to disappear out of View and no amount of pinching or dragging will bring it back into View.

So for now the project is on hold and i have more interesting stuff to work on.

Martin.
 
Top