Shawn
Shawn

Reputation: 127

android app's height/width is different in emulator than on device

I am running a couple of imageviews and a listview in an activity in my app. The display looks perfect in the emulator, which basically displays a short string, two small images at the top and then the rest of the screen consisting of the listview, but when I put it on my device (EVO3D) the listview is cutoff. In fact the width even seems slightly off.

Here is the layout.xml file;

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:orientation="vertical">

<TextView android:text="@string/showRunList_name" 
android:layout_width="wrap_content"  
android:layout_height="wrap_content" 
android:id="@+id/editText1">
</TextView>

<ImageView android:contentDescription="@string/auxLogo" 
android:id="@+id/imageView1" 
android:layout_height="wrap_content" 
android:src="@drawable/logo_small" 
android:layout_width="wrap_content"
android:layout_gravity="center">
</ImageView>

<ImageView android:contentDescription="@string/auxPhone" 
 android:id="@+id/imageView2" android:layout_height="wrap_content"
 android:src="@drawable/phone" android:layout_width="wrap_content">
</ImageView>

<TextView
android:id="@+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_no_items"/>

<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom|right"
/>
</LinearLayout>

Upvotes: 3

Views: 2512

Answers (4)

Paresh Mayani
Paresh Mayani

Reputation: 128428

Let me list out few points to take care off:

  1. You need to read this article: Supporting Multiple Screens.
  2. As you have described, image views are at top and the rest of the screen is covered by ListView, but you have defined android:layout_height="wrap_content" in parent , instead it should be android:layout_height="fill_parent" so it will be having full screen height.
  3. To make ListView to cover, rest of the screen, define android:layout_height="match_parent" or android:layout_weight="1".
  4. Use dp or dip instead of fixed size PX for defining measurements like height/width.
  5. Use sp (Scaled point) while defining font-size.

Upvotes: 1

devunwired
devunwired

Reputation: 63293

The resolution/aspect of your emulator is different than the device. The EVO3D has a resolution of 540x960. Your emulator is probably either HVGA (320x480) or WVGA (480x800). This slight variation causes the visible portion of your layout to shift somewhat.

Keep in mind your application will encounter many more device resolution/aspect ratio differences out in the market, so it should react appropriately to these changes.

HTH

Upvotes: 0

Sandy
Sandy

Reputation: 6353

You need to add multiscreen support properties into config files and also create different images as per the standard if you want to support multiscreen. Take a look here

Upvotes: 0

AD14
AD14

Reputation: 1218

check this http://developer.android.com/guide/practices/screens_support.html

Create emulators with same resolution as your device and test it.

Upvotes: 0

Related Questions