Android: how to make it no space between 2 button in a horizontal linearlayout

前端 未结 6 1128
情书的邮戳
情书的邮戳 2021-01-01 16:32

I just found I cannot remove the space between 2 buttons even if I set the layout_marginRight and layout_marginLeft as below. But it make sense if

相关标签:
6条回答
  • 2021-01-01 16:55

    Please look at Bryan's answer. With my answer both buttons overlap. Bryans answer shows the real size of the buttons.

    Old answer:

    Just set the android:layout_marginRight of the first button to "-8dip" or even more. Than the space between the two buttons will get smaller.

    0 讨论(0)
  • 2021-01-01 16:55

    You will have to set android:layout_marginRight="0dip" and you will have to remove the padding with android:paddingRight="0dip" for the other button this has to be changed to the left values. I guess you forgot that every android element has generally a padding added to it by default. This is generally a good idea, but if you want to remove it, this is the way.

    0 讨论(0)
  • 2021-01-01 17:03

    Use "layout_marginLeft" & "layout_marginRigh" to fill background button

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="bottom"
        android:orientation="horizontal" >
    
        <Button
            android:id="@+id/imageButton1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginBottom="-5dp"
            android:layout_marginLeft="-3dp"
            android:layout_marginRight="-4dp"
            android:layout_weight="1"
            android:drawableTop="@drawable/create_mail" />
    
        <Button
            android:id="@+id/bItem"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginBottom="-5dp"
            android:layout_marginLeft="-4dp"
            android:layout_marginRight="-4dp"
            android:layout_weight="1"
            android:drawableTop="@drawable/email_receive3"
            android:onClick="OnClick"
            android:text="@string/inbox" />
    
    
        <Button
            android:id="@+id/imageButton2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginBottom="-5dp"
            android:layout_marginLeft="-4dp"
            android:layout_marginRight="-3dp"
            android:layout_weight="1"
            android:drawableTop="@drawable/email_trash" />
    
    
    </LinearLayout>
    
    0 讨论(0)
  • 2021-01-01 17:04

    I think you can get rid of the space if you use TableLayout instead. And you can set negative values for the margin, if it's still adding some default space between them.

    0 讨论(0)
  • 2021-01-01 17:07

    You can switch to RelativeLayout. There is no spacing in that Layout.

    0 讨论(0)
  • 2021-01-01 17:10

    Try changing the color of the button, because the default interface of the button which is native to android is actually smaller than it's size, and it's center-fitted to make it look cool.

    Change it's background to black or something and you'll see the real size of the button.

    android:background="#000"
    
    0 讨论(0)
提交回复
热议问题