Android的:如何使它在一个水平LinearLayout中2键之间没有空格空格、使它、水平、Android

2023-09-07 10:14:18 作者:白闹.

我刚刚发现,即使我设置 layout_marginRight layout_marginLeft 如下面的2个按钮之间,我不能删除空格。但是,明智的,如果我设置空间较大,如10送稿器。 什么办法可以解决呢?

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:方向=横向机器人:填充=0dp
    机器人:layout_height =WRAP_CONTENT安卓重力=fill_horizo​​ntal机器人:layout_margin =0dp>
    <按钮机器人:ID =@ + ID / LocationTitleButton
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:layout_marginRight =0dp
                    机器人:layout_gravity =center_vertical
                    机器人:layout_weight =1
                    机器人:ellipsize =结束
                    机器人:重力=center_vertical
                    机器人:scrollHorizo​​ntally =真
                    机器人:单线=真
                    机器人:文本=添加位置
                    机器人:TEXTSTYLE =黑体/>
                <按钮机器人:文字颜色=#FF000000
                    机器人:layout_weight =0
                    机器人:ID =@ + ID / AddLocationButton
                    机器人:文本=搜索
                    机器人:重力=center_vertical
                    机器人:layout_gravity =center_vertical
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:layout_marginLeft =0dp/>
< / LinearLayout中>
 

解决方案

只需设置安卓layout_marginRight第一个按钮的 - 8DIP ,甚至更多。比两个按键之间的空间会越来越小。

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 I set the space larger such as 10 dp. Any way to solve it?

<?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>
Android怎么让LinearLayout的两个按钮之间存在一些间隔

解决方案

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.