Multi-screen layout issues

I am trying to develop an application that requires multi-screen support. I read an Android article on best practices for multi-screen support. In accordance with this article, we must follow 3 important things:

  • Mention support for various screen sizes (large, medium, and small) and any density in AndroidManifest.xml.
  • Place images with a resolution of 3 dpi (120, 160, 240) in 3 folders res / ldpi, res / mdpi and res / hdpi.
  • In the layout, the size should be indicated in units of "dip". Then Android will take care of scaling itself.

I implemented all these points in my project. Images are correctly selected from the corresponding folders. But the layout of the controls is not the same.

eg. I launched the application on three emulators


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

The problem is that the position of the controls is not the same on all three emulators. In my opinion, if android: layout_marginLeft and android: layout_marginTop are mentioned in "dip", then this problem should not occur. As the emulator density increases, the controls are placed closer to the right.

Is it absolutely imperative that I provide layouts for all combinations of screen size and density, even if the layout is the same for all devices?

Did I miss 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

+4
source share
3 answers

Yes, you should add the following to the manifest file: Reserves from ldpi, mdpi, orhdpi as needed

  <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> 
+3
source

First you calculate the height and width of the device

then if u wants the value 180 to be selected as the leftpadding value, and 48 as the toppadding value for the view, set it as

(320 / 1.8 = 1.77)

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

try it.

0
source

The problem is that the size of the devices increases the size of your image. Resize the images accordingly (increase the image size of mdp and ldpi). If you target the Nexus series, it will always target Xhdpi and hdpi, which is a real pain. you can also refer to my answer here: Android: multi-screen support

0
source

All Articles