nLL
nLL

Reputation: 5672

Android lyout stick buttons together

Here is my layout

    <LinearLayout
    android:id="@+id/toolbar"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/image"
    android:layout_gravity="bottom"
    android:layout_marginTop="5dp"
    >


    <Button
        android:layout_weight="1.0"
        android:id="@+id/button1"
        style="@style/ActionButtonText"
        android:background="@drawable/action_button_left"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="Button" >
    </Button>

    <Button
        android:layout_weight="1.0"
        android:id="@+id/button1"
        style="@style/ActionButtonText"
        android:background="@drawable/action_button_center"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="Button" >
    </Button>

    <Button
        android:layout_weight="1.0"
        android:id="@+id/button1"
        style="@style/ActionButtonText"
        android:background="@drawable/action_button_center"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="Button" >
    </Button>

    <Button
        android:layout_weight="1.0"
        android:id="@+id/button1"
        style="@style/ActionButtonText"
        android:background="@drawable/action_button_right"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="Button" >
    </Button>

and this is how they look

enter image description here

What i am trying to do is remove gap between buttons so they look stuck together like this

enter image description here

I have played with padding and margins but couldn't get it working. How can I achieve it? Thanks

Upvotes: 0

Views: 1336

Answers (2)

MAC
MAC

Reputation: 15847

enter image description here

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="bottom"
    android:layout_marginTop="5dp" >


    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="Button" >
    </Button>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="-10dp" <------ it will work....( minus 10)
        android:layout_weight="1.0"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="Button" >
    </Button>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="-10dp"
        android:layout_weight="1.0"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="Button" >
    </Button>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="-10dp"
        android:layout_weight="1.0"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="Button" >
    </Button>

</LinearLayout>

Upvotes: 1

C. Leung
C. Leung

Reputation: 6318

add android:orientation="horizontal" to your LinearLayout

Upvotes: 0

Related Questions