【问题标题】:How to get rid of extra spacing in LinearLayout?如何摆脱 LinearLayout 中的额外间距?
【发布时间】:2011-04-21 16:51:17
【问题描述】:

我构建了一个使用 LinearLayout 的小部件,并在布局中放置了两个 TextView。 布局的重力是“顶部”。

问题是我在两个 TextView 之间有一个空格,我无法摆脱它。

    <TextView 
        android:id="@+id/Text01"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:gravity="bottom|center_horizontal" 
        android:text="blah blah"
        android:background="@android:color/transparent"
        android:textColor="#3e6eb4"
        android:textSize="11sp"
        />        

    <TextView 
        android:id="@+id/text02"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:gravity="top|center_horizontal" 
        android:text=""
        android:background="@android:color/transparent"
        android:textColor="#3e6eb4"
        android:textSize="14sp"
        android:padding="0sp"
        android:verticalSpacing="0sp"
        />

如您所见,我尝试将 padding 0 和 verticalSpacing 0 放在一起,但它们之间仍然有一个空格。

我该如何解决?

谢谢。

【问题讨论】:

  • 你的意思是两个TextView中文本之间的空格吗?
  • sp 通常用于字体大小,其他使用 dp。 *.com/questions/2025282/…
  • @Orsol:是的,两个TextView之间的垂直空间

标签: android spaces android-linearlayout


【解决方案1】:

您也可以尝试使用负边距(就像CSS :)

(我用我的应用程序做到了,效果很好)

<TextView
android:layout_marginTop="-10dp"
android:layout_marginBottom="0dp"
/>

希望这会有所帮助!

【讨论】:

    【解决方案2】:

    尝试设置以下属性:

    <TextView
    android:layout_marginTop="0dp"
    android:layout_marginBottom="0dp"
    />
    

    【讨论】:

      【解决方案3】:

      对于某些属性,您使用 sp 而不是 dp。仅将 sp 用于字体大小。 :)

      【讨论】: