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: 5,833
  • Java source - ScrollView2D.zip
    17.6 KB · Views: 1,748
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
The latest official libraries are included inside the IDE. So they get updated together with the IDE.

Why would you want to automatically update the libraries when you don't want to update the IDE? New versions may depend on the new IDE (and framework). It is also possible for new versions to introduce bugs or breaking changes.
 

mc73

Well-Known Member
Licensed User
Longtime User
The latest official libraries are included inside the IDE. So they get updated together with the IDE.

Why would you want to automatically update the libraries when you don't want to update the IDE? New versions may depend on the new IDE (and framework). It is also possible for new versions to introduce bugs or breaking changes.
Just interested in the network lib to be honest, but I guess you are right. Till now, everything works great with 1.90, and as I've mentioned already, looking closely to 2.00 issues. Sooner or later, I'll update, after all the class addition is really great :)
 

Informatix

Expert
Licensed User
Longtime User
Here's a new version (1.02, see post #1).

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.

I need your contribution:
- tell me if this new code works better than the previous one (some parts have been rewritten and maybe new bugs have been introduced);
- I don't know how I can set the scrollbars visible. "setHorizontalScrollbarEnabled" does not work. I suppose I have to define some attributes (e.g. android:scrollbars = "horizontal|vertical") but I'm a bit lost outside of B4A and pure Java. I'm not familiar with these styles/layouts in XML files and how you call them from your code.
 

Informatix

Expert
Licensed User
Longtime User
Here's a new version (v1.03):
I fixed all known bugs (including bugs found in ScrollView & HorizontalScrollView);
I added the scrollbars;
I added three new functions:
- ScrollbarsVisibility (sets the scrollbars visibility);
- FadingEdges (defines whether the edges should be faded when the view is scrolled)
- GiveFocusToFirstVisible (sets the focus to the first focusable view in the visible area of the ScrollView2D panel).

I found a big bug in Scrollview and HorizontalScrollview (the focus is not properly handled when the Scrollview panel contains other panels with focusable children), so I submitted a bug report to the Android developpers. I didn't report two other bugs (minor) because I'm not sure for now they will occur on every device, with every Android version (it depends on other classes and how they interact).
My library, of course, is free of all these bugs.

The example program shows that SV2D works very well as a Scrollview or a HorizontalView. You can replace these views in your app with no harm. The only difference (if you have Gingerbread or a later version): there's no glowing effect when you overscroll (because these functions are not available in API 7).

I NEED YOUR REPORT. Please tell me if everything works as expected on your device.

Fred
 

ukimiku

Active Member
Licensed User
Longtime User
Thank you for the library. It works on XPERIA S under Android 2.3.7.

Is there a way to fix the first column and scroll horizontally only the remaining columns?

Thank you.

Regards,
 

Informatix

Expert
Licensed User
Longtime User
Thank you for the library. It works on XPERIA S under Android 2.3.7.
Fine.

Is there a way to fix the first column and scroll horizontally only the remaining columns?
This view is just a scrolling container, nothing more. What you put inside it and how these children views work or interact with your app depends on you.

Fixing a column is not very complicated. Put the whole column in a panel separated from the other columns and move this panel with each scroll change (more precisely, your code goes in the ScrollChanged event and adjust the left property of the "fixed column" panel).
 

Informatix

Expert
Licensed User
Longtime User
So, is there a standard view within Android that does this, or is this just combining a Horz and a Vert Scrollview together and handling all the events and sizes?

Basically, it's a merge between a HorzSv and a VertSv, but since these views have their own logic, you have to change a lot of things to make that work nicely (sometimes, the view must act as a VertSv, sometimes as a HorzSv, and sometimes in a new manner with the two directions taken in account). I had to fix a few bugs too. In the latest API (Jelly Bean), they removed almost all the code setting the focus to a child. I don't know why (too many bugs?). I fixed the code to make it work as stated in the source code comments. That explains why it took me quite a full time week to do the library.

I need to know, now, if that works as expected on your device.
 

OlegVic

New Member
Licensed User
Longtime User
mainSlider.Initialize(Activity.Width, Activity.Hight*2,"mainSlider")

how i can increase invisible hight? (Ex.:Activity.Hight*3)
Whithout changing visible hight.

mainSlider.hight = Activity.Hight*3 - dont work. :( changing visible area.

RESOLVED: NEED TO USE mainSlider.PANEL.hight = Activity.Hight*3
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
mainSlider.Initialize(Activity.Width, Activity.Hight*2,"mainSlider")

how i can increase invisible hight? (Ex.:Activity.Hight*3)
Whithout changing visible hight.

mainSlider.hight = Activity.Hight*3 - dont work. :( changing visible area.

The width and height properties define the visible size of your ScrollView. If you want to change the dimensions of the inner panel, you must use the following properties:
mainSlider.Panel.Height
mainSlider.Panel.Width
 

rbw152

Member
Licensed User
Longtime User
ScrollView2D library documentation!

Hi guys

can someone please post a link to the scrollview2d documentation? I can see from this thread that there is some available as Informatix says he created some with Erel but where is it?

Thanks!
 

Informatix

Expert
Licensed User
Longtime User
Hi guys

can someone please post a link to the scrollview2d documentation? I can see from this thread that there is some available as Informatix says he created some with Erel but where is it?

Thanks!

ScrollView2D has only five specific functions. The other functions are common to all views. The specific functions are described in the short text help appearing in B4A when you start to type them (autocompletion).
 

johnaaronrose

Active Member
Licensed User
Longtime User
I have a photo (in a Bitmap Global variable) that I want to be able to scroll both horizontally & vertically in a space on the screen (as I don't want to use the whole screen) for which I specify the Left, Width, Top & Height. The Initialize method allows me to set the Width & Height. When I try to specify the Left & Top, I get a Java Language Null Pointer Exception. Is there any way that I can define the Left & Top where the photo will be displayed?
 

klaus

Expert
Licensed User
Longtime User
You can define the ScrollView properties Left, Top, Width and Height defining the area on the screen.
Then with HorizontalPosition and VerticalPosition you can set the image position or with the ScrollChanged event you get the current postion of the image.

Best regards.
 

johnaaronrose

Active Member
Licensed User
Longtime User
You can define the ScrollView properties Left, Top, Width and Height defining the area on the screen.
Then with HorizontalPosition and VerticalPosition you can set the image position or with the ScrollChanged event you get the current postion of the image.

Best regards.

The SV2DPhoto ScrollView2D view only occupies part of the screen (i.e. other views are present on most of the screen) & is NOT at the top left corner. I'm using the code below:
B4X:
SV2DPhoto.Initialize(ImageViewPhoto.Width, ImageViewPhoto.Height, "")
SV2DPhoto.Left = ImageViewPhoto.Left
SV2DPhoto.Top = ImageViewPhoto.Top
SV2DPhoto.HorizontalScrollPosition = ImageViewPhoto.Left/2
SV2DPhoto.VerticalScrollPosition = ImageViewPhoto.Top/2
Log("SV2DPhotoWidth="&SV2DPhoto.Width)
Log("SV2DPhotoHeight="&SV2DPhoto.Height)

The app compiles but at run time I get a java.lang.NullPointerException on the SV2DPhoto.Left statement.
 

Informatix

Expert
Licensed User
Longtime User
The SV2DPhoto ScrollView2D view only occupies part of the screen (i.e. other views are present on most of the screen) & is NOT at the top left corner. I'm using the code below:
B4X:
SV2DPhoto.Initialize(ImageViewPhoto.Width, ImageViewPhoto.Height, "")
SV2DPhoto.Left = ImageViewPhoto.Left
SV2DPhoto.Top = ImageViewPhoto.Top
SV2DPhoto.HorizontalScrollPosition = ImageViewPhoto.Left/2
SV2DPhoto.VerticalScrollPosition = ImageViewPhoto.Top/2
Log("SV2DPhotoWidth="&SV2DPhoto.Width)
Log("SV2DPhotoHeight="&SV2DPhoto.Height)

The app compiles but at run time I get a java.lang.NullPointerException on the SV2DPhoto.Left statement.

I'm sorry but I don't understand at all what you're trying to do. Upload the full code because this part of the code has no sense to me.
I wonder if you don't make a confusion between moving an image on screen and scrolling it (meaning you see it through a window and scrolls it inside this window). If you want to move an image, look at TouchImageView.
 
Top