2017-04-13 33 views
0

2個textviews之間默認的空間這是我的xml:如何減少在RelativeLayout的

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.MainActivity"> 
    <TextView 
    android:id="@+id/a" 
    android:textSize="@dimen/logo_text" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textColor="@color/dark_grey" 
    android:text="@string/a" /> 
<TextView 
    android:id="@+id/b" 
    android:layout_below="@id/a" 
    android:textSize="@dimen/logo_text" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textColor="@color/light_grey" 
    android:text="@string/b" /> 
</RelativeLayout> 

將導致它們之間有一定的空間兩行文字。我想擺脫這個空間,讓兩行字符串彼此更接近。那可能嗎?

+0

你能把所有的佈局文件嗎? –

+0

兩個元素之間沒有默認空間 - 其字面上爲0像素。如果你看到一些,它內置到你使用的字體中。 –

+0

我用我使用的實際代碼編輯了它。也許這是建立在我的主題? –

回答

1

我想擺脫這個空間,並有兩行字符爲 互相靠近

嘗試此附加android:includeFontPadding="false"textview減少文本之間的空間

<TextView 
    android:id="@+id/a" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:includeFontPadding="false" 
    android:text="HELLO" /> 

<TextView 
    android:id="@+id/b" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/a" 
    android:includeFontPadding="false" 
    android:text="GOOD JOB Buddy" /> 

編輯

還加android:layout_marginBottom="-3dp"頂級文本視圖@+id/a ...

它將強制縮小兩個文本視圖之間的差距。

+0

沒有什麼區別 - 我用我使用的實際代碼更新了我的編輯(只是這種情況省略的部分會產生任何差異) –

+0

嘗試爲頂部文本視圖添加'android:layout_marginBottom =「 - 3dp」'+/a' ... – rafsanahmad007

+0

做到了,謝謝! –