Drawing in a scrollable area

wdegler

Active Member
Licensed User
Longtime User
I wish to create a canvas and use it to draw in a scrollable area. The following sample code gives an error message reporting "Pnl" as an invalid parameter.

Dim SV As ScrollView
Dim Pnl As Panel
Dim Cnv As Canvas
Dim Rct As Rect

SV.Initialize(0)
Pnl=SV.Panel
Pnl.Height=32767
Cnv.Initialize(Pnl) 'invalid parameter reported here
Activity.AddView(SV,0,0,100%x,100%y)

Rct.Initialize(0,0,100%x,100%y)
Cnv.DrawRect(Rct,Colors.Black,True,1)

What would allow that rectangle to be scrolled? Can someone show me how this should be done?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should explicitly set the width of the inner panel:
B4X:
Sub Globals
   Dim SV As ScrollView
   Dim Pnl As Panel
   Dim Cnv As Canvas
   Dim Rct As Rect
End Sub

Sub Activity_Create(FirstTime As Boolean)
   SV.Initialize(0)
   Activity.AddView(SV,0,0,100%x,100%y)
   Pnl=SV.Panel
   Pnl.Height=1000dip
   Pnl.Width = SV.Width
   Cnv.Initialize(Pnl) 'invalid parameter reported here
   Rct.Initialize(0,0,100%x,100%y)
   Cnv.DrawRect(Rct,Colors.Red,True,1)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…