1

When I put a view on a layout, it automatically has some padding/margin on it.

See this picture:

alt text

The red rectangle show the space that the button takes. Note the empty space between the button and the red lines. That's the space in question.

What controls that space and how to I change it ?

It's messing up my lisview's button alignments!

The code for that layout:

    <Button 
        android:text="@+id/Button01" 
        android:id="@+id/Button01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/>

    <Button 
        android:text="@+id/Button02" 
        android:id="@+id/Button02"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/>
</LinearLayout>

1 Answer 1

6

The button has a default background set by Android. If you look at Android source code, you can find that the button's background has a transparent area around it. This is done in order to make it into a nine-patch drawable. So you cannot remove that padding unless you specify your own background drawable for the button.

Sign up to request clarification or add additional context in comments.

2 Comments

To clarify, the default button background is a nine-patch drawable, which is a special type of stretchable .png which also defines default padding for Views which use it.
@Reuben. Thanks. I tried to be clear, but this makes it much understandable and apt :) +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.