Android:如何使水平线性布局中的2个按钮之间没有空格

Geo*_*_BJ 17 android space button android-linearlayout

我刚刚发现我无法删除,即使我设置了2个按键之间的空间layout_marginRightlayout_marginLeft下面.但是如果我将空间设置得更大,例如10 dp,那就更有意义了.有什么方法可以解决吗?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:orientation="horizontal" android:padding="0dp"
    android:layout_height="wrap_content" android:gravity="fill_horizontal" android:layout_margin="0dp">
    <Button android:id="@+id/LocationTitleButton"
                    android:layout_width="wrap_content" 
                    android:layout_height="wrap_content"
                    android:layout_marginRight="0dp"
                    android:layout_gravity="center_vertical" 
                    android:layout_weight="1"
                    android:ellipsize="end" 
                    android:gravity="center_vertical"
                    android:scrollHorizontally="true" 
                    android:singleLine="true"
                    android:text="Add location" 
                    android:textStyle="bold" />
                <Button android:textColor="#FF000000" 
                    android:layout_weight="0" 
                    android:id="@+id/AddLocationButton" 
                    android:text="Search" 
                    android:gravity="center_vertical"
                    android:layout_gravity="center_vertical" 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                    android:layout_marginLeft="0dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Fra*_*nke 44

请看布莱恩的答案.我的回答两个按钮重叠.布莱恩斯答案显示按钮的实际大小.

老答案:

只需将android:layout_marginRight第一个按钮设置为"-8dip"或更多.比两个按钮之间的空间会变小.

  • @Muzammil:你能解释一下你的意见吗? (2认同)

Bry*_*n P 31

尝试更改按钮的颜色,因为android原生的按钮的默认界面实际上小于它的大小,并且它的中心适合使它看起来很酷.

将它的背景更改为黑色或其他东西,您将看到按钮的实际大小.

android:background="#000"
Run Code Online (Sandbox Code Playgroud)

  • 这应该是接受的答案.Franziskus的答案确实不是一个好习惯. (4认同)