Sliding Panels Help

woodpecker

Member
Licensed User
Hi folks,

I have been looking at the sliding panels tutorial but cannot work out to make it work with my 2 panels.

I have a Layout with both panels called 2panel, panels are called pnlLayout1 and pnlLayout2, I switch between them by setting Visible=True or False.

In Activity_Create(FirstTime As Boolean) I have:-

B4X:
Activity.LoadLayout("2panel")
pnlLayout1.Top=0
pnlLayout1.Left=0
pnlLayout1.Visible=True

pnlLayout2.Top=0
pnlLayout2.Left=0
pnlLayout2.Visible=False
How can I slide between these 2 panels with finger swipe?

TIA
 

nfordbscndrd

Well-Known Member
Licensed User
The post I linked to was not part of the original tutorial. It says:

[To slide by touching the screen...] Just add the following code to the Main activity (replace the existing Sub Globals):
and it gives the routine. Are you saying that you could not get that code to work either?
 

woodpecker

Member
Licensed User
The post I linked to was not part of the original tutorial. It says:



and it gives the routine. Are you saying that you could not get that code to work either?
As I said, I cannot see how to use the example code with *my panels*, that block of code is already in the example file.

I have added the core module and library etc but the example initialises panels in the code and I cannot see how to make it slide my panels that are built in the designer.

When I run it in the emulator I get nullpointer exception from the slidingpanels_initialize

As I said in my first post I cannot see how to use my 2 existing panels, I don't understand how the array dim for panels fits in with my panels in this code:-

B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Create the panels.
   'In this example we are just creating 8 "dummy" panels with different colors.
   'You can instead load a different layout to each panel.
   Dim panels(3) As Panel
   For i = 0 To panels.Length - 1
      panels(i).Initialize("panels")
      panels(i).Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
      Dim lbl As Label
      lbl.Initialize("")
      lbl.Text = "I'm Panel: " & i
      lbl.TextSize = 20
      lbl.TextColor = Colors.White
      panels(i).AddView(lbl, 20%x, 40%y, 60%x, 30dip)
      Activity.AddView(panels(i), 100%x, 0, 100%x, 100%y - 60dip) 'add the panel to the layout
      Activity.AddMenuItem("Panel #" & i, "Menu")
   Next
   'add the Left and Right button
   btnLeft.Initialize("Left")
   btnLeft.Text = "Left"
   activity.AddView(btnLeft, 10%x, 100%y - 55dip, 100dip, 50dip)
   btnRight.Initialize("Right")
   btnRight.Text = "Right"
   activity.AddView(btnRight, 60%x, 100%y - 55dip, 100dip, 50dip)
   
   '*****************************
   'Initialize the SlidingData object and set the array of panels.
   'Then we call SlidingPanels.Initialize to prepare the animation objects.
   'The last call to ChangePanel brings the first panel.
   sd.Initialize
   sd.Panels = panels
   SlidingPanels.Initialize(sd, SlidingDuration)
End Sub
 

Erel

Administrator
Staff member
Licensed User
Remove this code:
B4X:
   Dim panels(3) As Panel
   For i = 0 To panels.Length - 1
      panels(i).Initialize("panels")
      panels(i).Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
      Dim lbl As Label
      lbl.Initialize("")
      lbl.Text = "I'm Panel: " & i
      lbl.TextSize = 20
      lbl.TextColor = Colors.White
      panels(i).AddView(lbl, 20%x, 40%y, 60%x, 30dip)
      Activity.AddView(panels(i), 100%x, 0, 100%x, 100%y - 60dip) 'add the panel to the layout
      Activity.AddMenuItem("Panel #" & i, "Menu")
   Next
Change:
B4X:
sd.Panels = panels
To:
B4X:
sd.Panels = Array As Panel(pnlLayout1, pnlLayout2)
Make sure that both panels are visible. You will also need to set the panels left property to 100%x (the right edge of the screen).
 

woodpecker

Member
Licensed User
Thank you Erel,

My panels now slide with the buttons but not with a finger swipe.

I have the Panels_Touch sub in the code and the associated variables have been dimensioned.

I think my Panels maybe missing a touch event, I have generated the members which gives me:-

B4X:
Sub pnlLayout1_Touch (Action As Int, X As Float, Y As Float)

End Sub
Sub pnlLayout2_Touch (Action As Int, X As Float, Y As Float)
   
End Sub
I tried putting the Panels_Touch code in these events but still nothing??
 

woodpecker

Member
Licensed User
Can you post your complete project (File - Export as zip)?


I have attached the zip and cleaned it up a bit, in its current state it doesn't seem to touch slide and the menu switch panels seems to scroll in a loop if panel#2 is clicked.

Also does it need to have left and right buttons, I would like just to have touch swipe?

TIA

Hang on file is missing
 
Last edited:

woodpecker

Member
Licensed User
I have tried numerous things to get this working but cannot get it going with the panels from the designer, if I use the same code except add back sample code to generate the panels at startup it works fine, for some reason it won't slide my designer-constructed panels?

:sign0085:
 

woodpecker

Member
Licensed User
You should set the EventName property to: Panels
This will cause Sub Panels_Touch to handle the touch event.
Hi Erel,

I have changed the property as suggested, if I insert a third blank panel with no buttons that will touch slide now but the ones with buttons won't, is this because the touch is starting on a button and not the actual panel?

I also have the same problem with the menu selection, if I select the Panel#2 (or #3 with when using 3 panels) the panels scroll forever.
 
Top