Android Tutorial Supporting multiple screens - tips and best practices

Discussion in 'Tutorials & Examples' started by Erel, May 8, 2012.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question. If possible also upload your project (File - Export as zip).
     
  2. jamesnz

    jamesnz Active Member Licensed User

    If i need different layout for landscape and portrait and I set variant specific scripts for say ( 480 x 320) will this work on all devices of do i have to set a landscape layout for all sizes ?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    It will work on all devices. You can easily test it with the UI Cloud.
     
  4. jamesnz

    jamesnz Active Member Licensed User

  5. ArminKH

    ArminKH Well-Known Member

    Hi
    I have one problem
    When i use dip my view's width and height is different in vitrual device with density 1 and blue stack with density 1
    I think that's should be same on any density by using dip
    Is this wrong?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    It depends on how you measure the width and height.

    The physical size (which is the important factor) should be more or less the same. The number of pixels will not be the same.
     
    ArminKH likes this.
  7. ArminKH

    ArminKH Well-Known Member

    Erel my device has 540pixel with 1.5 scale rate in width but the width of vitrual device (320*480)is larger in real
    320>360????!!!!
     
  8. ArminKH

    ArminKH Well-Known Member

    I want dock an item in left top without any change in width or height so i use dip for example i have an item with 35*35 size in 320*480 (density 1) and i use 35dip for this
    But the physical size of item is different in some device with different density or in blue stack with density 1
    i know for example 30 pixel in density 1.5 should be 45 pixel but i think the physical size should not be different when we use dip
    Is this wrong?
     
    Last edited: Nov 2, 2014
  9. klaus

    klaus Expert Licensed User

    Don't confuse dpi (dots per inch) and dip (density independant pixels).
    So, the physical dimension for a given number of dips can be somewhat different.
     
    ArminKH likes this.
  10. ArminKH

    ArminKH Well-Known Member

    so how we can prevent from changing the dimension of viewes?
     
  11. klaus

    klaus Expert Licensed User

    What accuracy do you expect ?
    The physical dimensions are almost the same with dips but not exactly.
    According to the documentation 48dip is equal to about 9mm.
    To get the xdpi and ydpi values look at THIS post.
     
    ArminKH likes this.
  12. ArminKH

    ArminKH Well-Known Member

    plz see this screenshot

    t.png

    this is a button with 100dip*100dip dimensions
    but the physical size in vitrual device is too different with blue stack
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    You need to test the physical size on a real device.
     
    ArminKH likes this.
  14. klaus

    klaus Expert Licensed User

    As already written, dip values do not garantie exactly the same physical dimensions, that's how Android works.
    If you really need 'exact' physical dimensions (the routine is in the second link in my previous post) you should get the exact x and y dpi values and calculate the pixels needed.
    Are you sure that the dimensions of the virtual devices are correct ?
    Why do you want 'exactly' the same physical dimensions ?
     
    ArminKH likes this.
  15. ArminKH

    ArminKH Well-Known Member

    dimensions on phone<bluestack<vitrual device
    yes kluas its correct
    i want my top menu be same on every phone similar to viber or other apps
    can u attache for me a little example?
     
  16. klaus

    klaus Expert Licensed User

    I have never calculated exact physical dimensions because I don't bother if there are small differences.
    If you have a device with 3'' screen and another one with a 3.5'' screen both with a density of 1.
    The dimensions on the 3.5'' screen will be a bit bigger than on the 3'' screen.
    Not sure if the look on both devices with exactly the same physical dimensions will be good.
    Having the dimensions more proportional to the screen dimensions will look better.
    It's already not that simple to define good looking layouts for different screen sizes without adding a new parameter which, in my opinion, will only complicate the whole stuff.
     
    ArminKH likes this.
  17. ArminKH

    ArminKH Well-Known Member

    ok thank u very much klaus ;)
     
  18. MrKim

    MrKim Well-Known Member Licensed User


    RE: The scale values can be one of the following values: 0.75, 1.0, 1.33, 1.5 and 2.

    With Android 7 this is evidently no longer true. My 1280 X 800 Tablet, depending on how the new feature "Display Size" is set, returns a scale of .85, 1(default), 1.125, and 1.25.
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    Added a message about this being an old tutorial with a link to a new tutorial.
     
    MrKim likes this.
Thread Status:
Not open for further replies.
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