Android Question random label

Douglas Farias

Expert
Licensed User
Longtime User
how can i put a label random position on my screen

for exemple when start the app show

10% top 10% left

or 20% top
etc
random
its possible?
 

Douglas Farias

Expert
Licensed User
Longtime User
with Label1.Left = caca&"%y" xD
CACA is a random rnd(0,99) result

and this dont work
Rnd(0,99)%y
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
if help someone ;)

B4X:
Dim lado,alto As Int
lado = GetDeviceLayoutValues.Width
alto = GetDeviceLayoutValues.Height
r1 = Rnd(0,lado)
r2 = Rnd(0,alto)

    Label1.Left = r1
    Label1.top = r2
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Just limit the width and height so the label doesn't disappear off the screen:

B4X:
r1 = Rnd(0,lado - Label1.Width)
r2 = Rnd(0,alto - Label1.Height)
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
xD
when I went to post you posted first
thx man

i see this problem because i have my label out of screen
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The label will disappear or look incomplete in case the number is zero.

0,0 is top left, you should be able to see all of the label. It may not be where you want it though. Limiting to borders is a good idea.
 
Upvote 0
Top