B4J Library [B4X] [XUI] SD XUIScrollView2D

I develop the cross-platform version of the ScrollView2D library.
XUIScrollView was developed all from scratch.
xScrollView is a wrapping of the native ScrollView but which standardizes the commands so that they can be used cross-platform.
Everyone can choose which one is best suited to their purpose

NOTE: You can use this library for personal and commercial use. Include it in your projects.. Attention, even if it is a B4XLib library, it is not allowed to decompress it, modify it, change its name or redistribute it without the permission of the author

SD_XUIScrollView2D

Author:
Star-Dust
Version: 0.12
  • XUIScrollView
    • Events:
      • ScrollChanged (X As Float, Y As Float)
    • Fields:
      • Tag As Object
    • Functions:
      • AddView (View As B4XView, Left As Int, Top As Int, Width As Int, Height As Int)
      • BringToFront
      • DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
        Base type must be Object
      • FullScroll (Bottom As Boolean)
      • GetAllViewsRecursive As List
      • GetBase As B4XView
      • GetView (Index As Int) As B4XView
      • Initialize (Callback As Object, EventName As String)
      • Initialize2 (Callback As Object, EventName As String, PanelParent As B4XView, Width As Int, Height As Int)
      • Invalidate
      • LoadLayout (LayoutFile As String)
      • NumberOfViews As Int
      • Parent As B4XView
      • RemoveAllViews
      • RemoveViewFromParent
      • RequestFocus
      • ScrollPositionX (X As Float)
      • ScrollPositionY (Y As Float)
      • SendToBack
      • SetBitmap (bmp As B4XBitmap)
      • SetColorAndBorder (Backgroundcolor As Int, BorderWidth As Int, BorderColor As Int, BorderCornerRadius As Int)
      • SetColorAnimated (Duration As Int, FromColor As Int, ToColor As Int)
      • SetLayoutAnimated (Duration As Int, Left As Int, Top As Int, Width As Int, Height As Int)
      • SetPanelBitmap (bmp As B4XBitmap)
      • SetRotationAnimated (Duration As Int, Degree As Int)
      • SetVisibleAnimated (Duration As Int, Visible As Boolean)
      • Snapshot As B4XView
    • Properties:
      • Color As Int
      • Enable As Boolean
      • FastScroll As Boolean
      • Height As Int
      • HorizontalBar As Boolean
      • Left As Int
      • Panel As B4XView [read only]
      • PanelHeight As Int
      • PanelWidth As Int
      • PositionX As Float
      • PositionY As Float
      • Top As Int
      • VerticalBar As Boolean
      • Visible As Boolean
      • Width As Int
  • xScrollView
    • Events:
      • ScrollChanged (X As Double, Y As Double)
      • ScrollChangedX (X As Double)
      • ScrollChangedY (Y As Double)
    • Fields:
      • Tag As Object
    • Functions:
      • AddToParent (MainPane As B4XView, Left As Int, Top As Int, Width As Int, Height As Int)
        Create from codice
      • AddView (View As B4XView, Left As Int, Top As Int, Width As Int, Height As Int)
      • BringToFront
      • DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
        Base type must be Object
      • FullScroll (Bottom As Boolean)
      • GetAllViewsRecursive As List
      • GetBase As B4XView
      • GetView (Index As Int) As B4XView
      • Initialize (Callback As Object, EventName As String)
      • IsInitialized As Boolean
      • LoadLayout (LayoutFile As String)
      • NativeObject As Object
      • NumberOfViews As Int
      • Parent As B4XView
      • RemoveAllViews
      • RemoveViewFromParent
      • RequestFocus
      • SendToBack
      • SetBitmap (bmp As B4XBitmap)
      • SetColorAndBorder (Backgroundcolor As Int, BorderWidth As Int, BorderColor As Int, BorderCornerRadius As Int)
      • SetColorAnimated (Duration As Int, FromColor As Int, ToColor As Int)
      • SetLayoutAnimated (Duration As Int, Left As Int, Top As Int, Width As Int, Height As Int)
      • SetPanelBitmap (bmp As B4XBitmap)
      • SetRotationAnimated (Duration As Int, Degree As Int)
      • SetVisibleAnimated (Duration As Int, Visible As Boolean)
      • Snapshot As B4XView
    • Properties:
      • Color As Int
      • Enable As Boolean
      • Height As Int
      • HorizontalBar As Boolean
      • Left As Int
      • Panel As B4XView [read only]
      • PanelHeight As Int
      • PanelWidth As Int
      • PositionX As Double
      • PositionY As Double
      • Top As Int
      • VerticalBar As Boolean
      • Visible As Boolean
      • Width As Int


video1-gif.81039


__________________________________________________
Log version
0.02

Rounded scroll bars
0.03
Fix bugs of bars
Add B4J Version
0.04
B4XLib now
BUGS flicker correction
0.06
BUGS flicker correction
0.07
Add RemoveAllViews method
0.08
Fix bugs. Add Panel member
0.09
Fix bugs.
0.11
Touch interception improved.
0.12
New class added. XScrollView. It uses the native scrollView classes (ScrollView2D for b4a) by standardizing the use
fix bugs (B4a)
Updated examples (B4XPages)
0.13
fix bugs
 

Attachments

  • Sample_xScrollView.zip
    15.1 KB · Views: 304
  • Sample_XuiScrollView2D.zip
    19.8 KB · Views: 302
  • SD_XUIScrollView2D.b4xlib
    6.3 KB · Views: 209
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Update to rel. 0.07
Add RemoveAllViews method

Update to rel. 0.08
Fix bugs. Add Panel member
 
Last edited:

johnmie

Active Member
Licensed User
Longtime User
Thanks, Stardust. This fills a long awaited need. BUT
your example contains several controls, but when trying to add a click event it says "current module does not support layout events". Why and how to enable?
Best, john m.
 

TelKel81

Active Member
Licensed User
How to catch touch events on the inner panel ? I have to initialize a panel inside the inner pannel ?
 

Star-Dust

Expert
Licensed User
Longtime User
Internal panel events cannot be intercepted. They are used internally.

Add a panel and intercept the touch.
 

TelKel81

Active Member
Licensed User
I added a panel to the inner pannel, however the panel intercepts the touch event, so scrolling doesn't work after that. I would like to be able to scroll but still detect events such as click/tap.

I could use Gesture Detector (B4A) on the inner pannel to counter this problem, but I want to make my app "B4X".

Any suggestion ?
 

Star-Dust

Expert
Licensed User
Longtime User
Are you using Sd_ScrollView2d.Initialize2?

If possible post a sample code so I understand your problem
 

TelKel81

Active Member
Licensed User
1- No -- I add XUIScrollView with the designer and use LoadLayout.

2- I fill the inner panel with other panels, and then I can't scroll through the inner panel, because those panels intercept any touch event.
 

Star-Dust

Expert
Licensed User
Longtime User
1- No -- I add XUIScrollView with the designer and use LoadLayout.

2- I fill the inner panel with other panels, and then I can't scroll through the inner panel, because those panels intercept any touch event.
Now I understand the problem, it's a classic problem, in iOS it doesn't happen.
In Android (or at least in b4a) the panel absorbs all the events of the view even those it does not use such as dragging.

Days ago I thought about a method that overcomes this obstacle, if I always have the development.
However, it has no relation to my library in particular, but to all scrollviews or panels in general
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

Star-Dust

Expert
Licensed User
Longtime User
No touch listener will be added if you don't implement the touch or click events.

I don't know how you implemented the library but it must be based on ViewsEx.TouchPanelCreator for it to work in more complex cases.
You can see an example here: https://www.b4x.com/android/forum/t...pe-actions-and-pull-to-refresh.98252/#content
Sure, but I think he implemented the click in the upper panels.
Obviously as you pointed out, if no events are implemented they are not absorbed.

That's why I wanted an example of the code, to better understand
 

TelKel81

Active Member
Licensed User
If that helps :
After setting a listener (via Gesture Detector) on XUIScrollView's inner panel, I can't scroll the inner panel anymore.
After setting a listener (via Gesture Detector) on ScrollView2D's inner panel, I can still scroll the inner panel.

To me it seems like XuiScrollView doesn't listen "on top" of other listeners, while ScrollView2D seems to do that.

That would also explain why ScrollView2D allows me to scroll through its inner panel even when it's filled with other views that catch events.
 

Star-Dust

Expert
Licensed User
Longtime User
If that helps :
After setting a listener (via Gesture Detector) on XUIScrollView's inner panel, I can't scroll the inner panel anymore.
After setting a listener (via Gesture Detector) on ScrollView2D's inner panel, I can still scroll the inner panel.

To me it seems like XuiScrollView doesn't listen "on top" of other listeners, while ScrollView2D seems to do that.

That would also explain why ScrollView2D allows me to scroll through its inner panel even when it's filled with other views that catch events.
I honestly don't understand what you want to tell me. The inner panel does not listen to the events of the panels above him. Each view/panel generates its own event and is managed individually.

Give an example of what you want to achieve. You can try using XCustomListView
 

TelKel81

Active Member
Licensed User
B4X:
Sub Process_Globals
    Private xui As XUI
End Sub

Sub Globals
    Private canvas As B4XCanvas
    Private sv As XUIScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("XUIScrollView")
    'Activity.LoadLayout("ScrollView2D")
    sv.Panel.Width = sv.Width * 2
    sv.Panel.Height  = sv.Height * 2
    canvas.Initialize(sv.Panel)
    canvas.DrawCircle(sv.Width / 2, sv.Height / 2, sv.Width / 2, xui.Color_Blue, True, 0)
    sv.Panel.AddView(xui.CreatePanel("test"), 0, 0, sv.Panel.Width, sv..Panel.Height)
End Sub

Activity.LoadLayout("XUIScrollView") : can't scroll
Activity.LoadLayout("ScrollView2D") : can scroll
 

Star-Dust

Expert
Licensed User
Longtime User
It works perfectly for me. I am attaching the example and the result.

Video.gif
 

Attachments

  • TestScroll.zip
    10.2 KB · Views: 318

Star-Dust

Expert
Licensed User
Longtime User
Sorry for the delay.

It stops working if you add :

B4X:
Sub test_Click
End Sub

@Erel has already answered you about this.
No touch listener will be added if you don't implement the touch or click events.
.... it must be based on ViewsEx.TouchPanelCreator for it to work in more complex cases...
So Erel, with his interesting solution, is explaining to you that by creating your panel with TouchPanelCreator you can intercept the panel touch event but not absorb the movement.

Please read carefully the very useful interventions that are in this thread you will not need anything else.
 
Last edited:
Top