Android Question Sliding panels

stari

Active Member
Licensed User
Longtime User
I have a problem vith sliding panels. I try to create imageview on every panel, but this don't work. Only 1 image i can create.
B4X:
Sub Activity_Create(FirstTime AsBoolean)
'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) AsPanel

For i = 0To panels.Length - 1
panels(i).Initialize("panels")
panels(i).Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
Dim lbl AsLabel
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)

Dim slika AsImageView
slika.Initialize ("Slika")

If i = 0Then
slika.Bitmap = LoadBitmap(File.DirAssets ,"front_page_crn.png")
EndIf

If i = 1Then
slika.Bitmap = LoadBitmap(File.DirAssets ,"sleep_crn.png")
EndIf

If i = 2Then
slika.Bitmap = LoadBitmap(File.DirAssets ,"concentrate_crn.png")
EndIf

panels(i).AddView (slika, 0,0,100%x,100%y)

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)
sd.targetPanel = -1
sd.currentPanel = currentPanelBeforePaused - 1
ChangePanel(True) 'Current code expects the first call to be with Left = True.
End Sub

[code]
 

Attachments

  • slidingp.zip
    88.3 KB · Views: 328

Erel

B4X founder
Staff member
Licensed User
Longtime User
Correct code:
B4X:
Dim panels(3) As Panel
   Dim images() As String = Array As String("front_page_crn.png", _
     "sleep_crn.png", "concentrate_crn.png")
   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)
     
     Dim slika As ImageView
     slika.Initialize ("Slika")
     slika.Bitmap = LoadBitmapSample(File.DirAssets, images(i), 100%x, 100%y)
     slika.Gravity = Gravity.FILL
     panels(i).AddView (slika, 0,0,100%x,100%y - 60dip)
     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)
 
Upvote 0

stari

Active Member
Licensed User
Longtime User

Thks, Erel.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…