Android Question Align lables over an imageview so it looks good on all devices

Discussion in 'Android Questions' started by Sub7, Feb 16, 2015.

  1. Sub7

    Sub7 Active Member Licensed User

    Hello,
    how is possible to aling correctly label_1, label_2 and imageview_2 shown in the example so it will looks in the same position in all devices?

    -Views are added from the designer

    I use the designer script to dock, align, and set the width accordling the activitysize (i use a panel docked left and right to 0%x,100%x) Then i dock the views to this panel and other elements so the layout is adapted accordling to the device screen size, the layout looks good on tablets, phones, small phones, no problems

    But with one exception
    , these labels and imageview_1 change postion (up/down) depending on device.

    What's wrong?

    Here a piece of script from designer:

    Code:
    'The height of the panel is set later
    'Panel
    pnl_1.Top = 0%y
    pnl_1.SetLeftAndRight(
    0%x,100%x)

    'Imageview_1
    imageview1.Top = pnl_1.Top +5dip
    imageview1.SetLeftAndRight(
    5%x,95%x)
    imageview1.Height = imageview1.Width

    'Label_1
    label_1.Top = imageview1.Top+10%y
    label_1.SetLeftAndRight(imageview2.Left+
    10dip,imageview2.Right-10dip)

    'Imageview_2
    imageview2.Top = label_1.Bottom+5dip
    imageview2.SetLeftAndRight(imageview1.Left+
    29%x, imageview1.Right-29%x)
    imageview2.Height = imageview2.Width

    'Label_2
    label_2.Top = imageview2.Bottom+5dip
    lablel_1.SetLeftAndRight(imageview2.Left+
    10dip,imageview2.Right-10dip)

    pnl_1.height = imgeview_1.height + 
    ' and so on.
    This script is written here it may have some errors.
     

    Attached Files:

    • LIB.jpg
      LIB.jpg
      File size:
      49.1 KB
      Views:
      75
  2. walterf25

    walterf25 Well-Known Member Licensed User

    You should use percentages everywhere instead of dip.
     
  3. Sub7

    Sub7 Active Member Licensed User

    like
    Code:
    label_2.Top = imageview2.Bottom+2%y
    That's all? thanks.
     
  4. walterf25

    walterf25 Well-Known Member Licensed User

    Yes
     
    Sub7 likes this.
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