Android Question 20 very different label

AlpVir

Well-Known Member
Licensed User
Longtime User
There will be the opportunity to create from code 20 labels, all with different properties Color and TextColor ?
The end result should be 20 label as different as possible between them visually.
This using Colors.RGB (r, g, b)
Something like
B4X:
For i = 1 to 20
  Label (i).Color = Colors.RGB (a,b,c)
  Label (i).TextColor = Colors.RGB (x,y,z)
next

Thanks in advance
 

Mark Read

Well-Known Member
Licensed User
Longtime User
Maybe this from SteveIO5 would be of help.

B4X:
Sub Globals
    Dim lblWoord() As Label
End Sub

Sub Activity_Create
    'When you Know how many there are
    Dim Count As Int = 10
    Dim lblWoord(Count) As Label                'still a global variable
    For i = 0 To Count-1
        Dim L As Label
        L.Initialize("lblWoord")
        L.TextColor = Colors.black
        L.TextSize = 16
        L.Tag = i
        lblWoord(i) = L
    Next
 
    For Each L As Label In lblWoord
        Log(L.Tag)
    Next
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
    For i = 0 To 99
        Dim lbl As Label
        lbl.Initialize("label")
        Dim posx As Int = Rnd(0,100%x-50dip)
        Dim posy As Int = Rnd(0,100%y-50dip)
        Dim zufall As Int = Rnd(1, 101)
        Dim col As Int
        col = Colors.ARGB(Rnd(100, 150),Rnd(20, 800),Rnd(80, 160),Rnd(161, 255))
       
        Dim col2 As Int
        col2 = Colors.ARGB(Rnd(100, 150),Rnd(20, 800),Rnd(80, 160),Rnd(161, 255))

        'Log("Zufall: "&zufall)
        'Log("PosX: "&posx)
        'Log("PosY: "&posy)
        lbl.Text = zufall
        lbl.Tag = zufall
        lbl.TextColor = col2
        lbl.Color = col
        Activity.AddView(lbl,posx,posy,50dip,50dip)
    Next
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Thanks but that's not what I asked.
Your code relies entirely on the function RND ()
It may therefore happen that creates two labels with different colors identical or very little different.
If you want the label visually very different necessary that the values of R, G and B of Colors.RGB function (x, y, z) are determined by the code.
Example
Colors.RGB (R * K1 + F1, G * K2 + F2, B * K3 + F3)
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
What about creating an array with say 20 color combinations where you hardwire the colors yourself? Then you could set the color quite easily calling
B4X:
lbl.textcolor=Colors.RGB(array(i,1),array(i,2),array(i,3)) in a for-next loop for i (in post#3).

One problem that I see is that there are only 16 really clear different colors. But this might help:

http://www.rapidtables.com/web/color/RGB_Color.htm
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Very useful page with various colors. Thank you!
However, the problem remains unsolved: what values of R, G, B choose to maximize the visible difference of the label?
Probably I will do everything by hand, with subsequent adjustments.
It should be experts in the "Color Theory".
If the label were a number greater than 20 may be rather laborious.
The problem (from the theoretical point of view) remains unresolved.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
This has been discussed many times on Internet. Google is your friend. Example: http://stackoverflow.com/a/4382138.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…