Android Question View Canvas activity

strupp01

Active Member
Licensed User
Longtime User
I want to get any canvas line drawn immediately.
Today, he only shows the whole drawn when the loops are completely through. Below is a small example program.
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim Panel1 As Panel
    Dim Canvas1 As Canvas
    Dim Start, Ende As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Start")



    Canvas1.Initialize(Panel1)   

    For l=0 To 10   
        Start= l*30
        Ende= Start+20
        For i = 1 To 5000 Step 4
            Canvas1.DrawLine(i, Start, i+2, Ende, Colors.Red, 1dip)

            Canvas1.DrawLine(i+2, Ende, i+4, Start, Colors.Red, 1dip)
        Next
    Next
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

klaus

Expert
Licensed User
Longtime User
When you want a Canvas drawing being shown you need to Invalidate the parent view.
In your case Panel1.Invalidate.

What exactly do you want to achieve?
You are using dip values and pure pixel values?
It seems that you are drawing a zigzag line with 5000 Vs, which is much wider than any screen width!

Attached a modified version.

Drawing code with a Sleep to show a timing:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Start")

    Canvas1.Initialize(Panel1)   
    
    Private i, l, j As Int
    For l = 0 To 10   
        Start= l * 30dip
        Ende = Start + 20dip
        For i = 1 To Panel1.Width / 1dip Step 4
            j = DipToCurrent(i)
            Canvas1.DrawLine(j, Start, j + 2dip, Ende, Colors.Red, 1dip)

            Canvas1.DrawLine(j + 2dip, Ende, j + 4dip , Start, Colors.Red, 1dip)
            Panel1.Invalidate
            Sleep(10)
        Next
    Next
End Sub
 

Attachments

  • B4A_Canvas1.zip
    6.9 KB · Views: 313
Upvote 0

strupp01

Active Member
Licensed User
Longtime User
Thanks for your help. Have a curve of medical data generated, but only at the end was displayed. the command 'Panel1.Invalidate' also showed no effect. Now I know that this was due to followers of Sub's must work here with 'WaitFor'.
 
Upvote 0
Top