代码之家  ›  专栏  ›  技术社区  ›  Ran

如何消除线性布局中的多余间距?

  •  5
  • Ran  · 技术社区  · 14 年前

    我已经构建了一个使用线性布局的小部件,并且在布局中放置了两个文本视图。 布局的重心是“顶部”。

    问题是我在两个文本视图之间找到了一个空间,但我无法摆脱它。

        <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"
            />
    

    如你所见,我尝试了填充0和垂直填充0,但它们之间仍然有一个空格。

    我怎么修?

    谢谢。

    3 回复  |  直到 12 年前
        1
  •  9
  •   Lior Iluz    14 年前

    你也可以尝试使用负的边缘(就像 CSS :)

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

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

    希望这有帮助!

        2
  •  0
  •   DavGin    14 年前

    尝试设置以下属性:

    <TextView
    android:layout_marginTop="0dp"
    android:layout_marginBottom="0dp"
    />
    
        3
  •  0
  •   epicness42    12 年前

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