Android Question What's is wrong with this Designer Script?

Discussion in 'Android Questions' started by incendio, Mar 29, 2015.

  1. incendio

    incendio Well-Known Member Licensed User

    Hi all,

    I have a problem with designer script for SetTopAndBottom command (Sample project Attached)

    In my layout, there is pnlMain, pnlMain contains 3 panels, pnlTitle, pnlInput & pnlTbl.
    pnlTbl contains 1 panel, pnlData.

    On each panels, SetTopAndBottom command seem OK, but on pnlData is not OK.

    Here is the sample on designer script :
    pnlMain.Width = 100%x
    pnlMain.Height = 
    pnlTitle.Width = pnlMain.Width

    pnlTitle.Top = 
    pnlInput.SetTopAndBottom(pnlTitle.Bottom + 

    pnlTbl.SetTopAndBottom(pnlInput.Bottom + 
    5dip,pnlMain.Bottom - 5dip)

    8dip,pnlTbl.Bottom -15dip)
    'pnlData.Top = 8dip
    'pnlData.Height = pnlTbl.Height -15dip
    The last command pnlData.SetTopAndBottom(8dip,pnlTbl.Bottom -15dip) is supposed to set pnlData bottom 15dip above pnlTbl bottom, but it was not correct.

    Anybody knows what is wrong with those codes?

    Thanks in advance.

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    pnlData is a child of pnlTbl. So its coordinates are relative to pnlTbl.
    The correct code is:
    pnlData.SetTopAndBottom(8dip,pnlTbl.Height -15dip'height instead of bottom
  3. incendio

    incendio Well-Known Member Licensed User

    What about pnlTbl?

    This panel is a child of pnMain, yet a command
    pnlTbl.SetTopAndBottom(pnlInput.Bottom + 5dip,pnlMain.Bottom - 5dip) return a correct result.
  4. Erel

    Erel Administrator Staff Member Licensed User

    This is also a mistake. However pnlMain.Top is 0 so you don't see it.
  5. incendio

    incendio Well-Known Member Licensed User

    Ok, thanks for your explanation.
  6. Cableguy

    Cableguy Expert Licensed User

    That's because PlMain has the same size as the Parent activity.
    SetTopAndBottom and SetLeftAndRight set their positions relative to its parent, so if its parent has a top and bottom of 10%y,90%y its has a 80%Y height, setting one of its childs to hava a botton equal to the parent's 90%y will make it offset by 10%y
    That's why it is so easy and yet so tricky to use the scripts... everything can and should be relativized... with caution
  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