B4A Library [Lib] ScrollView2D

Hello,

Does it need a long explanation ? You can scroll in the two directions.

This lib does not work with Android versions < 2.

v1.01:
I fixed a big bug in the original code.
I added the function SmoothScrollTo.

v1.02:
I restarted from a fresh basis because of the many bugs in the original code. I fixed most of them (now, multitouch events and hardware keys are correctly handled) but a few are left and need more work (sometimes the wrong object get the focus and resizing is not perfectly handled). I noticed by the way that the stock scrollview is bugged and does not set the focus correctly if you move your finger very slowly.
Thanks to Erel, I solved the problem with the B4A documentation.
I added a new function: FullScroll.

v1.03:
I fixed all known bugs (including bugs found in ScrollView & HorizontalScrollView);
I added the scrollbars;
I added three new functions:
- ScrollbarsVisibility
- FadingEdges
- GiveFocusToFirstVisible.

v1.1:
I fixed a problem with events that were not fired if declared in a class;
I added two functions: ScrollingIsFinished and DisableTouchEventInterception.

v1.2:
SV2D appears now as a custom view in the designer with all its properties.

v1.3:
I fixed a bug (SV_2 = SV_1 did not work because the inner panel was declared in the wrong class).

Enjoy,
Fred
 

Attachments

  • ScrollView2D v1.3.zip
    120.5 KB · Views: 3,860
  • Java source - ScrollView2D.zip
    17.6 KB · Views: 760
Last edited:

fabioferreiracs

Member
Licensed User
is possible map touch event in scrollview2d ? i use a bitmap in scrollview2d background and I need to know what position was touched (x and y)
 

keirS

Well-Known Member
Licensed User
I cat get this library to work in Marshmallow 6.01 using your example code when I scroll I get.
B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setAlpha(int)' on a null object reference
    at flm.b4a.scrollview2d.EdgeEffect.draw(EdgeEffect.java:320)
    at flm.b4a.scrollview2d.TwoDScrollView.draw(TwoDScrollView.java:1997)
    at android.view.View.draw(View.java:16096)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16094)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16094)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16094)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16187)
    at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2690)
    at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2728)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2642)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2434)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2067)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
    at android.view.Choreographer.doCallbacks(Choreographer.java:670)
    at android.view.Choreographer.doFrame(Choreographer.java:606)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I tried disabling edge effects but it still crashes.
 

Informatix

Expert
Licensed User
I cat get this library to work in Marshmallow 6.01 using your example code when I scroll I get.
B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setAlpha(int)' on a null object reference
    at flm.b4a.scrollview2d.EdgeEffect.draw(EdgeEffect.java:320)
    at flm.b4a.scrollview2d.TwoDScrollView.draw(TwoDScrollView.java:1997)
    at android.view.View.draw(View.java:16096)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16094)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16094)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16094)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16187)
    at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2690)
    at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2728)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2642)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2434)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2067)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
    at android.view.Choreographer.doCallbacks(Choreographer.java:670)
    at android.view.Choreographer.doFrame(Choreographer.java:606)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I tried disabling edge effects but it still crashes.
Please download the latest version from this forum and try again.
 

jimmykuss

Member
Licensed User
Hello,

i use b4a V3.20 and can not run the demo (see picture). I got some errors(log) and have no idee.
Can you help me?
Thanks
JK
 

Attachments

  • log.PNG
    log.PNG
    49.3 KB · Views: 80

vbmundo

Well-Known Member
Licensed User
Hi,

I quit the old Table.Bas from my Proyect and add this new Table2.0

But when compile I have error at this line

Private cTextSize As Float
Type RowCol (Row As Int, Col As Int)
Private cAlignment As Int

"An item with the same key is added."

What's wrong ?

Regards
 

klaus

Expert
Licensed User
I have a problem with the GetType function for ScrollView2D.Panel in version 1.2 of the library.
I get this error
Error occurred on line: 44 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4a.objects.PanelWrapper.getObject()' on a null object reference
at b4a.example.main._activity_create(main.java:431 ...

in this line: Log(GetType(sc2.Panel)) ' error in this line

The code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
 
    Log(GetType(scvTest))
    Log(GetType(scvTest.Panel))
    InitScrollView2D
    Log(GetType(sc2Test))
    Log(GetType(sc2Test.Panel)) 'this works
 
    For i = 0 To Activity.NumberOfViews - 1
        Private v1 As View
        v1 = Activity.GetView(i)
        Log(GetType(v1))
        If GetType(v1) = "anywheresoftware.b4a.objects.ScrollViewWrapper$MyScrollView" Then
            Private scv As ScrollView
            scv = v1
            Log(GetType(scv.Panel))
        Else If GetType(v1) = "flm.b4a.scrollview2d.ScrollView2DWrapper$MyScrollView" Then
            Private sc2 As ScrollView2D
            sc2 = v1
            Log(GetType(sc2.Panel)) ' error in this line
        End If
    Next
End Sub

Attached a small test program.

The code above works with version 1.1 of the library.
 

Attachments

  • ScrollView2D_GetType.zip
    7.8 KB · Views: 97

Informatix

Expert
Licensed User
I have a problem with the GetType function for ScrollView2D.Panel in version 1.2 of the library.
I get this error
Error occurred on line: 44 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4a.objects.PanelWrapper.getObject()' on a null object reference
at b4a.example.main._activity_create(main.java:431 ...

in this line: Log(GetType(sc2.Panel)) ' error in this line

The code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")

    Log(GetType(scvTest))
    Log(GetType(scvTest.Panel))
    InitScrollView2D
    Log(GetType(sc2Test))
    Log(GetType(sc2Test.Panel)) 'this works

    For i = 0 To Activity.NumberOfViews - 1
        Private v1 As View
        v1 = Activity.GetView(i)
        Log(GetType(v1))
        If GetType(v1) = "anywheresoftware.b4a.objects.ScrollViewWrapper$MyScrollView" Then
            Private scv As ScrollView
            scv = v1
            Log(GetType(scv.Panel))
        Else If GetType(v1) = "flm.b4a.scrollview2d.ScrollView2DWrapper$MyScrollView" Then
            Private sc2 As ScrollView2D
            sc2 = v1
            Log(GetType(sc2.Panel)) ' error in this line
        End If
    Next
End Sub

Attached a small test program.

The code above works with version 1.1 of the library.
Yes, this is normal. The Panel is not created until the SV2D is initialized.
 
Top