Search code examples
androidxmlscreen-size

android screen size resoulution


I have made an app for the screen size resoulution 480x800px(I have all my layouts and ImageButtons in the drawable-hdpi folder and I have used dp instead of px), in the xml I used layout_marginLeft and marginTop to place all the buttons and everything.. When i run my app in the emulator on 480x800 it is perfect, but if i change the screen size and resoulution all buttons changes place and size on the screen. I am very frustrated cause i have no idea what to do to make it fit all screen sizes and resoulutions what so ever? Any tips?

What different sizes should i use in different folders? I have 480x800 in hdpi, what should i have in xhdpi?


Solution

  • You have to maintain different layouts for different screens. For example:

    res/layout/my_layout.xml             // layout for normal screen size ("default")
    res/layout-small/my_layout.xml       // layout for small screen size
    res/layout-large/my_layout.xml       // layout for large screen size
    res/layout-xlarge/my_layout.xml      // layout for extra large screen size
    res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
    
    res/drawable-mdpi/my_icon.png        // bitmap for medium density
    res/drawable-hdpi/my_icon.png        // bitmap for high density
    res/drawable-xhdpi/my_icon.png       // bitmap for extra high density
    

    Add this one in manifest.xml

    <supports-screens android:smallScreens="true" 
          android:normalScreens="true" 
          android:largeScreens="true"
          android:xlargeScreens="true"
          android:anyDensity="true" />
    

    Check this link: http://developer.android.com/guide/practices/screens_support.html

    For best UI design, you should maintain Relative layout instead of LinearLayout.

    See this:

    For example: you want to display one image.. Then, now you need to maintain the same image in different sizes for different screens.

    36x36 for low-density
    48x48 for medium-density
    72x72 for high-density
    96x96 for extra high-density
    

    3:4:6:8 scaling ratio