Android Question [SOLVED] Set Equal Position of Views in Panel

Discussion in 'Android Questions' started by konradwalsh, Apr 12, 2018.

  1. konradwalsh

    konradwalsh Active Member Licensed User

    Hi
    I have searched and search and cannot find a specific answer to my question;

    I have a panel. It may have 1 checkbox or up to 8.
    I add the checkbox dynamically.

    How can I position them so that it goes
    1 2 5 6
    3 4 7 8

    This is the code I have used to achieve this:
    Code:
    If i Mod 2 <> 1 Then
             panLive_ListedUsers.AddView(userCheckBox,posLeft + 
    5dip, posTop + 10dip , 100dip30dip)
             posLeft = posLeft + 
    100dip
     
    Else
              panLive_ListedUsers.AddView(userCheckBox,posLeft + 
    5dip, posTop + 10dip100dip30dip)
               posTop = posTop + 
    30dip
                           
     
    End If
    [​IMG]
     

    Attached Files:

  2. klaus

    klaus Expert Licensed User

    This is one possibility:
    To add the texts, use an array of string.
    Code:
    Private Space As Int = 5dip
    Private Width As Int = Min(100dip, (panLive_ListedUsers.Width - 5 * Space) / 4)
    Private Height As Int = 30dip
    Private posLeft As Int
    Private i, j, k As Int
    For i = 0 To 1
        
    For j = 0 To 1
            k = 
    2 * i + j
            posLeft = Space
            
    Private userCheckBox As CheckBox
            userCheckBox.Initialize(
    "userCheckBox")
            userCheckBox.Tag = k
            userCheckBox.Text = k + 
    1
            panLive_ListedUsers.AddView(userCheckBox, posLeft + j * (Width + Space), Space + i * (Height + Space), Width, Height)
            
            k = k + 
    4
            posLeft = 
    3 * Space + 2 * Width
            
    Private userCheckBox As CheckBox
            userCheckBox.Initialize(
    "userCheckBox")
            userCheckBox.Tag = k
            userCheckBox.Text = k + 
    1
            panLive_ListedUsers.AddView(userCheckBox, posLeft + j * (Width + Space), Space + i * (Height + Space), Width, Height)
        
    Next
    Next
     
    DonManfred, konradwalsh and Erel like this.
  3. konradwalsh

    konradwalsh Active Member Licensed User

    Perfect Solution.. Thanks for your help
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice