1

I created a layout with the prebased (480x800) density. I have been using this since I started learning android (9 mths) and now it was time to test my app on other phones. I tested it on three phones with 480x800 resolution and was fine, until I tested it on one with 320x480 and 240x320. I have used px-s as width and height, paddingTop etc. everywhere. I checked the app in the emulator (created different avd-s for different resolutions) and I cannot see the whole layout, as it is bigger than the screen (testing it only in eclipse). It has 4 images with "wrap_content" width and height settings. So I checked the android documentation. I have not created other layouts or anything else, but replaced the px-s with dp-s. It is the same. I created smaller buttons (see below) with 190x60px resolution and put them into the ldpi folder, but there was no big advance. Maybe because the textsizes of the textviews are the same and the 2 textviews takes 1/3 of the place of the display in case of the 240x320 resolution (while only 1/6 in case of the 480x800). (So the texts look huge in the small resolution compared to the large resolution) Please tell me what should I do to make the layout look in this 320x480 resolution like in the 480x800.

Size of gradientbg: this is an .xml file for a shape, so no physical size. Size of buttons (images): 380x150px hdpi (or 190x60px in ldpi folder)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/gradientbg"
    >
    <TextView 
        android:id="@+id/TextView00"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#E30000"
        android:textColor="#FFFFFF"
        android:gravity="center_horizontal|center_vertical"
        android:textSize="26dp"
        android:height="40dp"
        android:textStyle="bold"
        android:text="Main menu"
    />
    <TextView  
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="App"
        android:textSize="30dp"
        android:textStyle="bold"
        android:paddingTop="20dp"
        android:layout_gravity="center_horizontal"
        android:textColor="#FFB300"
    />
    <Button android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
            android:background="@drawable/mainbutton_1"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dip"
    />
    <Button android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/mainbutton_2"
        android:layout_gravity="center_horizontal"
        android:paddingTop="5dp"
    />
    <Button android:id="@+id/btn3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
                android:background="@drawable/mainbutton_3"
        android:layout_gravity="center_horizontal"
        android:paddingTop="5dp"
    />
    <Button android:id="@+id/btn4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
                android:background="@drawable/mainbutton_4"
        android:layout_gravity="center_horizontal"
        android:paddingTop="5dp"
    />

</LinearLayout>
alain.janinm
  • 19,951
  • 10
  • 65
  • 112
erdomester
  • 11,789
  • 32
  • 132
  • 234
  • Create different layouts for different sizes. You can look at this question: http://stackoverflow.com/questions/5726764/android-layouts-for-multiple-screen-sizes – James Black Oct 17 '11 at 19:46
  • 1
    Pixel density and screen size are completely different things. If you put resources in the ldpi folder, they won't necessarily be used on small screens; for that, you would need to put them in the small folder. See the topic [Supporting Multiple Screens](http://developer.android.com/guide/practices/screens_support.html) for more info. – Ted Hopp Oct 17 '11 at 20:12
  • Ok. Which one is the better practice? To create buttons (images) in different sizes or is it enough (right) to set the width and height to a proportional (e.g. 380dp for hdpi, 190dp for ldpi) size. Last one is easier and works, but I am curious. – erdomester Oct 18 '11 at 05:38

1 Answers1

0

When you normally define layouts in dp units, you ensure that the layout stays the same on devices in the same density bucket. But when you try it on a tablet (xlarge) or a small screen, it won't scale right. This tool is made to have your app work with the whole range of devices (small/normal/large/xlarge). It scales your layout xml-files from the baseline density you were originally designing for.

http://onemanmobile.blogspot.com/2012/04/how-to-scale-your-android-layouts-to.html

Andreas Rudolph
  • 1,226
  • 19
  • 28