Android Question Drawing regardless of the device?

Jerryk

Member
Licensed User
Longtime User
I have this code: in a loop I draw circles while changing the distance between them. Next to it I have a reference line from 0 to 75%y. On the 10" emulator, the circles reach roughly 50% of the reference line, on the 4" emulator they are beyond the end of the line.
How to make it so that they reach the same % reference line regardless of the device?

B4X:
Private Sub Button2_Click
    Dim x, vx As Float
    canvas.DrawLine(0, 300dip, 75%x, 300dip, Colors.Blue, 5dip)    'reference line
    x = 0dip
    vx = 17dip   'initial step
    For i = 1 To 50
        vx = vx * 0.95   'shortening the step
        x = x + vx
        canvas.Drawcircle(x, 310dip, 5dip , Colors.Green, True, 0)
        Activity.Invalidate
    Next
End Sub
 

Attachments

  • Screenshot_1717943327.png
    Screenshot_1717943327.png
    10.6 KB · Views: 75
  • Screenshot_1717943253.png
    Screenshot_1717943253.png
    6.7 KB · Views: 74
Solution
I have this code: in a loop I draw circles while changing the distance between them. Next to it I have a reference line from 0 to 75%y. On the 10" emulator, the circles reach roughly 50% of the reference line, on the 4" emulator they are beyond the end of the line.
You have used an incorrect algorithm
The reference line is a percentage relative to the width
When drawing a circle, you used an absolute step size
How to make it so that they reach the same % reference line regardless of the device?
Set initial step vx as a percentage of width, such as vx=2.5%x

teddybear

Well-Known Member
Licensed User
I have this code: in a loop I draw circles while changing the distance between them. Next to it I have a reference line from 0 to 75%y. On the 10" emulator, the circles reach roughly 50% of the reference line, on the 4" emulator they are beyond the end of the line.
You have used an incorrect algorithm
The reference line is a percentage relative to the width
When drawing a circle, you used an absolute step size
How to make it so that they reach the same % reference line regardless of the device?
Set initial step vx as a percentage of width, such as vx=2.5%x
 
Last edited:
Upvote 0
Solution
Top