I'm trying to draw a button with an image as background. Here's my xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="13dp"
android:background="@drawable/button_bg"
android:text="Break Record"
android:textColor="#2c4417"
android:textSize="19dp"
android:textStyle="bold" >
</Button>
</LinearLayout>
On the graphical layout view, it looks as I intended:
But on the emulator, the button takes the entire width of the screen:
I've read the specification more than once, but couldn't get what my mistake is,
How do I write the button xml so that the button will look on the emulator (and all devices..) as in the Eclipse's Graphical Layout?
Thanks.
The width of button is due to @drawable/button_bg
. If the background image is constant for different densities then hdpi would should button small in size, on the other hand, mdpi and ldpi devices would take more width to show the same button. Confirm that you have different background images and they are relative to their densities.
P.S. Run three different emulators with hdpi, mdpi and ldpi densities respectively and observe the layout.