Android Question Layout fine in designer, but not on device

Discussion in 'Android Questions' started by Arf, Mar 19, 2015.

  1. Arf

    Arf Active Member Licensed User

    I've got a layout that includes an ImageView which shows a background picture and I draw graphs over it.
    I have 2 variants in the designer only - generic 7" portrait and the same in landscape (960*600), scale 1.
    In the designer I have width and height settings for the panel as 601x680.

    In the portrait designer script I set the ImageView for width = 100%x and adjust the height and position to maintain aspect ratio.

    In landscape I set it for height = 100%y and adjust the width and position to maintain aspect ratio.

    All works fine on 7" tablet. I've got AutoScale on. If I connect my smaller samsung S3 phone to the Designer and run the designer script, it displays fine on the phone.

    However when I actually run the app on the phone, when the phone is horizontal, the ImageView width is as wide or a little wider than the screen, and vertically I can see less than half of it.

    The phone resolution is 800*480 in landscape, 1.5 (240dpi)

    Can't figure out why, the scripts for that bit are dead simple. I named the imageView Axes.
    Portrait:
    Code:
    Axes.Width = 100%x
    Axes.Height = Axes.Width*
    528/460
    Landscape:
    Code:
    Axes.Height = 100%y
    Axes.Width = Axes.Height*
    460/528
    Is it perhaps something to do with the ImageView size settings in the designer?
     
  2. NJDude

    NJDude Expert Licensed User

    You have to use DIP like:
    Code:
    Axes.Height = Axes.Width * 528dip / 460dip
     
  3. klaus

    klaus Expert Licensed User

    Axes.Height = Axes.Width*528/460
    and
    Axes.Height = Axes.Width * 528dip / 460dip
    will give the same result.
    Do you also adjust the Left and Top properties ?

    Can you post a small project showing thw problem.
     
  4. Arf

    Arf Active Member Licensed User

    I don't adjust LEFT and TOP, but the anchor points in the designer for Axes is left, top.
    I tried SetTopAndBottom(0%y, 100%y) instead of just setting height but the outcome was the same.

    I have attached a project with just this element in it.
    Thanks guys.
     

    Attached Files:

  5. klaus

    klaus Expert Licensed User

    Attached a modified version.
    It seems that in landscape the program doesn't read the correct layout.
    Instead of calculating the dimensions in the specific layout sections I moved them to the 'All variants' section, testing wether the device is in portrait or landscape.
     

    Attached Files:

    NJDude likes this.
  6. Arf

    Arf Active Member Licensed User

    Thanks Klaus, I'll check it out.

    Do you think it's something to do with B4A that is stoping the correct layout being picked up, or something to do with the device?
    It works fine on all the larger devices I've tried it on, just not the galaxy phone.
     
  7. klaus

    klaus Expert Licensed User

    I don't know.
    Another point in your layout.
    You set AutoScaleRate after AutoScaleAll, you should invert them, set AutoScaleRate before AutoScaleAll.
    But event with this change it didn't solve your problem, I saw it too on my Sony xperia z1.
     
    Arf likes this.
  8. Arf

    Arf Active Member Licensed User

    I have swapped the Scale Rate and Scale All is in your example now.
    It is working now on all my devices, thanks for the help :)
     
  9. Troberg

    Troberg Well-Known Member Licensed User

    Nope. When divided to a ratio like that, it becomes unitless.
     
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