siva636
siva636

Reputation: 16441

Android margin not working as expected

Consider the following code and output:

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

    <Button
        android:id="@+id/button1"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="A" />

    <Button
        android:id="@+id/button2"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="B" />

    <Button
        android:id="@+id/button3"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="C" />

</LinearLayout>

enter image description here

Because android:layout_margin="0dp", the buttons should touch each other, but this is not happening. Please explain this behavior. What can I do to eliminate the gap between the buttons?

Upvotes: 0

Views: 306

Answers (1)

Labeeb Panampullan
Labeeb Panampullan

Reputation: 34823

That is due the style applied to the button.
You can avoid that by setting android:background but you will loose the click effect and all .

Upvotes: 1

Related Questions