简体   繁体   English

2个按钮之间的LinearLayout间距

[英]LinearLayout space between 2 buttons

this is my linearLayout: 这是我的linearLayout:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="ANNULLA"
        android:id="@+id/button4"
        android:layout_gravity="bottom"
        android:textColor="#FFF"
        android:background="#87a914"
        android:textStyle="bold"
        android:textSize="20dp"
        android:layout_marginBottom="2dp"
        android:layout_marginLeft="3dp" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="SALVA"
        android:id="@+id/button5"
        android:layout_gravity="bottom"
        android:textColor="#FFF"
        android:background="#87a914"
        android:textStyle="bold"
        android:textSize="20dp"
        android:layout_marginBottom="2dp"
        android:layout_marginRight="3dp" />
</LinearLayout>

and this the result: 结果是:
在此处输入图片说明
I would like to have a space between the button "SALVA" and the button "ANNULLA" 我想在按钮“ SALVA”和按钮“ ANNULLA”之间留一个空格
i mean something like that: 我的意思是这样的:
在此处输入图片说明

只需在第二个按钮中添加此属性

android:layout_marginLeft="xdp" 

我最喜欢的方法是在按钮之间添加不可见视图,如下所示:

<View android:layout_width="5dp" android:layout_height="wrap_content" android:visibility="invisible" />

One way is to add an empty View in between them with a suitable weight 一种方法是在它们之间以合适的weight添加一个空View

<View
    android:layout_width="0dp"
    android:layout_height-"wrap_content"
    android:layout_weight=".2"/>  // change this to what works for you

your width for the Buttons should be "0dp" when using layout_weight 使用layout_weight时, Buttonswidth应为“ 0dp”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM