4
votes

I am trying to develop an app for which I want multiple screen support. I have read the Android article on Best practices for Multiple Screen Support. As per the article we have to follow 3 important things:

  1. Mention support for different screen sizes(large, medium and small) and any density in AndroidManifest.xml.
  2. Place images of 3 dpi's (120, 160, 240) in 3 folders res/ldpi, res/mdpi and res/hdpi.
  3. In layout's the dimension should be mentioned in "dip" units. Then Android will take care of the scaling on its own.

I have implemented all these points in my project. The images are picked up correctly from the appropriate folders. But the arrangements of the controls in not same.

e.g. I ran the app on three emulators


1. Resolution 240*320 dpi 120.
2. Resolution 240*320 dpi 160.
3. Resolution 240*320 dpi 240.
(All the emulator have same resolution but different density. )

The problem is the position of the controls is not same on all the three emulator. As per my understanding if the android:layout_marginLeft and android:layout_marginTop are mentioned in "dip" then this problem should not occur. As the density of the emulator increases the controls get placed more towards the right.

Is it absolutely necessary that i provide layouts for all combination's of screen dimension and density even if the layout is same for all the devices?

Am I missing some important point?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
  <ImageView android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:src="@drawable/bgd" android:scaleType="fitXY">
    </ImageView>
   <ImageView android:id="@+id/wtButton"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:src="@drawable/button" android:layout_marginLeft="170dip"
        android:layout_marginTop="9dip"></ImageView>
    <ImageView android:id="@+id/htButton"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:src="@drawable/button2" android:layout_marginLeft="220dip"
        android:layout_marginTop="90dip"></ImageView>
</RelativeLayout>

Images:

https://docs.google.com/leaf?id=0By3GYC3k5AMDNzUwNjkwMWEtOGQzZC00MjQ0LWE2OTgtYjFhYzZmM2ExOGVl&hl=en&authkey=CLOEsZsI

3
Would you please post up some example screenshots and your layout XML.Octavian A. Damiean
Silly thought: You don't think it IS actually scaling correctly and just the emulator cannot display multiple density sizes correctly? (which would make sense, the emulator can't exactly change the pixels on your physical screen, only scale to 'emulate' the various densities)Dororo
Had the same problem, any luck finding answerSnake

3 Answers

3
votes

Yes you have to ADD the following thing in the manifest file then only it will take the Resorces from the ldpi,mdpi,orhdpi as per need

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

    <compatible-screens>
 <screen
            android:screenDensity="mdpi"
            android:screenSize="mediaum" />      
  <screen
            android:screenDensity="hdpi"
            android:screenSize="large" />
        <screen
            android:screenDensity="xhdpi"
            android:screenSize="large" />
    </compatible-screens>
0
votes

First you calculate device height and width

then if u want set 180 as leftpadding value and 48 as toppadding value for view, then set it as

(320 /1.8 = 1.77)

meterView.setPadding((int) (width/1.8), (int) (height/10), 3, 5);

try this.

0
votes

The problem is as the size of the devices increase your image size decrease. Re-size your images accordingly (increase mdp and ldpi image's size). If you wnat to target Nexus series, it would always target Xhdpi and hdpi, which is a real pain. you can also refer to my answer here : Android: support multiple screens