androidresolutionscreens

Android screen in different resolutions


I want to develop an app which will support different screen sizes.

I've read the official guide a lot of times, but I can not understand this. I created a brand new app with a main activity, then I put a black square on the screen with 100dp x 100dp dimensions, just like this:

res/layout/activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#000000"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
         />


</RelativeLayout>

When I run this application on my emulator - I get this screen: enter image description here

And when I run the application on my device (Galaxy tab 2), I get a screen like this: enter image description here

As you can see, the square running on device is smaller than running on the emulator.

I am using DP in my XML width and height. Is the square supposed to be in the same proportion in all resolutions? If not, what can I do to get this square in the same size in all resolutions?


Solution

  • Yes, this can be confusing. However, different devices have different amounts of 'DP's. The purpose of this is so that larger screens can hold more content. If you're using images, you can provide different sizes for different screen densities.

    For more info, see this page: http://developer.android.com/guide/practices/screens_support.html