how to distinguish two different android mdpi phones

835 views Asked by At

Im trying to write app witch will look similar on all (or most) android phones. I have a problem with two phones: Samsung Galaxy Ace 2 and Samsung Galaxy mini 2. Layout that takes whole screen in galaxy ace is too large for galaxy mini.

First I tried to specify different dimens for ldpi and mdpi, but it appeared that both phones used mdpi values. Then I was trying too distinguish them by screen sizes and made folder values-normal-mdpi. I thought that ace should be "large", it has 480x800 resolution and should be large accordinng to documentation: Supporting Multiple Screens. However both phones take values from the "normal-mdpi" folder. On the other hand I have seen application that look identical on both phones, how can I do this?

Edit:

imagine I have a very simple layout only with simple views:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<Button
    android:id="@+id/button4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<Button
    android:id="@+id/button5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
    android:id="@+id/button6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" /></LinearLayout>

The last button is not visible on smaller phone. What shoud I do if I want this to look identical on both?

3

There are 3 answers

2
Phantômaxx On BEST ANSWER

Well, it turns out that none of the two is an mdpi device:
Samsung Galaxy Ace 2: WVGA (480x800) resolution (about 244 dpi) = hdpi
Samsung Galaxy Mini 2: QVGA (240×320) resolution (about 127 dpi) = ldpi

So, the drawable folders for your graphics should be:
res/drawable-ldpi
res/drawable-hdpi

Please note that you should provide pngs at the proper resolutions (120 and 240 dpi).
You can choose to provide a normal resolution graphics (160 dpi, which is mdpi) and it will be scaled to 120 dpi (0.75x) for ldpi devices and to 240dpi (2.0x) for hdpi devices

1
GLee On

You shouldn't really need to use different dimensions for different screen sizes, except in special cases. Instead, use the attributes in your layout.xml to define how the elements in your layout should scale. For instance, android:layout_width = "match_parent" will always match that element's width to the width of the parent, no matter what the screen size. Check out this link about xml layouts to get started.

1
Junior Buckeridge On

I think is a very good practice the use of dimensions but you must choose your classifiers properly. You must know that ldpi, mdpi, hdpi, xhdpi and xxhdpi stand for the density of pixels in the screen of devices. In this case you're exposing, you may wanna try the "smallest width" classifier. For example, if you have 2 screens, both mdpi, but one of them is 240 dips width and the other is 320 dips, you should place dimensions under the folders "values-sw240dp" and "values-sw320dp".

Hope it helps.