Why are button sizes on Eclipse vs Device not the same
O.k....this is weird. I had my buttons looking fine last week, now something has changed.
My buttons on the eclipse emulator are much larger than on my device (Droid 2.1).
I checked my skin settings, screen size permissions, density factors....what am I missing?
My skin is set to WVGA854, but when the app goes to the phone the buttons are smaller!? Text and pictures are fine...looking the same as the emulator...just the buttons are shrunk!
Hmm....I know it has to be something simple...:)
UPDATE: Ok....posting xml;
<RelativeLayout 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/pic">
<Button
android:id="@+id/strtbtn"
android:textSize="8pt"
android:layout_marginTop="50px"
android:layout_marginLeft="20px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blahh"/>
<Button
android:id="@+id/contbtn"
android:textSize="8pt"
android:layout_marginTop="140px"
android:layout_marginLeft="200px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blahh"/>
<Button
android:id=开发者_JAVA百科"@+id/credbtn"
android:textSize="8pt"
android:layout_marginTop="530px"
android:layout_marginLeft="20px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blahh"/>
<Button
android:id="@+id/miscbtn"
android:textSize="8pt"
android:layout_marginTop="610px"
android:layout_marginLeft="80px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blahh"/>
<Button
android:id="@+id/blahhbtn"
android:textSize="8pt"
android:layout_marginTop="690px"
android:layout_marginLeft="200px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blahh"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/introanim"
android:id="@+id/introanim"
android:layout_gravity="center"
android:layout_weight="1"/>
</RelativeLayout>
Instead of using the "px" unit for your dimensions, use "dip". Or better, use wrap_content. The WVGA emulator uses a higher density. 10px on a high density (240dpi) display will look 1.5x times smaller than on a medium density display (160dpi.) To make them look the same, one would use 10dip instead. 10dip = 10px on medium density displays, and 15px on high density displays.
All the information you need can be found there: http://d.android.com/guide/practices/screens_support.html
Hmm, if you had said it the other way around, I've have agreed. For me, sometimes the WVGA854 emulator craps out and shows everything in a tiny size on the screen. It's as if it's showing everything according to the 320x480 size, but since the screen is 2.5x bigger it's all too small. Unfortunately, you seem to have a different problem... Does restarting Eclipse and the emulator make any difference to the button sizes? That does it for me when the problem happens.
Or here's another idea - have you installed a custom theme on your phone? If your app uses default button drawables, then installing a new theme will have changed those. That could explain why you're seeing different things on your phone and emulator.
My view on best practice for Android sizing. In your AndroidManifest.xml
<supports-screens android:largeScreens="true"
android:normalScreens="true" android:smallScreens="true"
android:anyDensity="true" android:resizeable="true" />
Then throughout your layouts use dip (Device Independent Pixel) units for your measurements.
I think it may have something to do with the Droid 2.1 update. The buttons in my apps got smaller once I downloaded the new version of Android.
精彩评论