Android Question Get .Top and .Left positions for Buttons created with relative positions

Discussion in 'Android Questions' started by Batman_, Apr 21, 2019.

  1. Batman_

    Batman_ Member Licensed User


    I have a Designer script that positions some Buttons with "Relative" positioning and I want to animate them using the Animation library. For this I require the .Top and .Left positions as I want to animate them horizontally and not from the top left of the screen. Note: .Left position isn't really required as I will use 0 but the principle holds. The Designer script code for the positioning of the Imageviews:
    IconButton_B.Top=IconButton_A.Bottom + 
    IconButton_C.Top=IconButton_B.Bottom + 
    IconButton_D.Top=IconButton_C.Bottom + 
    However when I run this code to get the co-ordinates I only get the .Top from the first Button and not the other Buttons.
    'Refresh UI so can calculate location of Buttons
    For I= 0 To 3
    "Sub: SecondScreen.Activity_Create(). IconButtonCoordinates Array - Button:= " & Starter.IconButtonCoordinates(I,0),Colors.Blue)
    "Sub: SecondScreen.Activity_Create(). IconButtonCoordinates Array - Top:= " & Starter.IconButtonCoordinates(I,1),Colors.DarkGray)
    "Sub: SecondScreen.Activity_Create(). IconButtonCoordinates Array - Left:= " & Starter.IconButtonCoordinates(I,2),Colors.Magenta)
    In the log I get returned (see attached image).

    I believe it is some kind of timing issue as the Buttons draw correctly (see attachment) on screen in their relative positions (as per Designer script). I just can't get access to the positions myself.

    I believe a Callback is required (read on a java forum)? But I don't know what to do and I have no java knowledge. See attachment for Java answer to my problem.

    Attached Files:

    Last edited: Apr 21, 2019
  2. Erel

    Erel Administrator Staff Member Licensed User

    No callback is required. The positions should be correct immediately after the call to LoadLayout.
  3. Batman_

    Batman_ Member Licensed User


    I have no issue with the icon buttons positioning correctly.

    I wanted to get the .Top position of each Icon Button so I can use the Animation library to animate them horizontally and not from the top left of screen. I want the icon buttons to appear to move sideways from the left of screen not from the top left of screen. For this I needed the .Top position for each Icon Button to set the start position of each Icon Button.

    Anyhow, it does seem to be an issue with timing and not being able to get correct co-ordinates to store in an array (or single variables).

    I have now put a time delay using this function (see code):
    Sub Delay(nMilliSecond As Long)
    Dim nBeginTime As Long
    Dim nEndTime As Long
        nEndTime = 
    DateTime.Now + nMilliSecond
        nBeginTime = 
    Do While nBeginTime < nEndTime
            nBeginTime = 
            If nEndTime < nBeginTime Then
    End If
    End Sub
    and set it to 5 nMilliSecond.

    By using this time 5 nMilliSecond delay I can get the array (and/or single variables) to get the .Top correctly with the .Top value of each Icon Button rather than populate with 0 that happens without the delay.

    I don't know if this is a hack or what I should be using but it works.
  4. Erel

    Erel Administrator Staff Member Licensed User

    You should never use DoEvents.

    You also don't need to use the animation library. Just call view.SetLayoutAnimated.

    The simplest way for us to help you is if you upload a small project with the layout.
  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