tags:

views:

489

answers:

3

When I created a button view, Android always create some extra space between this button and other views below it.

In this example below, there is a button above the second button. You can see the gap between these two buttons. How can I get rid of this gap? Thanks.

<?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="wrap_content">

    <Button android:id="@+id/up"
        android:layout_width="fill_parent" android:layout_height="28dip"
        android:textSize="9sp" android:gravity="center" android:text="Hide sth"
        android:layout_marginBottom="0" android:paddingBottom="0" />
    <Button android:id="@+id/down"
        android:layout_width="fill_parent" android:layout_height="28dip"
        android:textSize="9sp" android:gravity="center" android:text="Show sth" />
   </LinearLayout>
+2  A: 

Create your own button background nine-patch PNG that eliminates the space. You can find the existing background files in your SDK.

CommonsWare
A: 

Hi CommonsWare, Thanks for your replay. Could you give me some details on how to make it? I copied a button.9.png image from SDK to my project, and changed the layout as below, but still saw the gap between buttons. Could you help me out? Thanks.

<?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="wrap_content">

    <Button android:id="@+id/up"
        android:layout_width="fill_parent" android:layout_height="28dip"
        android:textSize="9sp" android:gravity="center" android:text="Hide sth"
        android:layout_marginBottom="0dp" android:paddingBottom="0dp"
        android:background="@drawable/button"  android:height="28dip"
        android:maxHeight="28dip" />
    <Button android:id="@+id/down"
        android:layout_width="fill_parent" android:layout_height="28dip"
        android:background="@drawable/button"
        android:layout_marginBottom="0dp" android:paddingBottom="0dp"
        android:textSize="9sp" android:gravity="center" android:text="Show sth" />
</LinearLayout>
A: 
jagsaund