2012-08-09 81 views
5

我有1英寸高的文字,但視圖框佔用1.5英寸,所以白色字母上方和下方有1/4英寸的黑色空間。我想減少1/4英寸,這樣我就可以在我的6英寸屏幕上獲得5行文本,而不是隻有4行。我可以使用android:lineSpacingMultiplier =「。66」將它們移近一些,但這只是將這些框更靠近一起和1/4英寸的黑色空間覆蓋附近的行的文本。 android:includeFontPadding =「false」什麼都不做。負填充什麼都不做。放在android:lineSpacingExtra =「 - 50sp」中也只是黑邊覆蓋了相鄰的文本行。我想擺脫邊際(實際上,只是大部分)。如何減少Android xml佈局中文本的填充?

我已經嘗試了所有我能想到的選項,包括上面討論的填充和邊距以及填充(包括零和負數)的顯而易見的選項。我無法找到顯示實際文本上方視圖中控制空間的簡單圖。

如何減少浪費的空間?

(我的互聯網斷了最後2小時,我花了一些時間來作出迴應對不起。)

這裏是我的XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<TextView 
    android:id="@+id/textTimer" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:includeFontPadding="false" 
    android:text="10.01" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textSize="@dimen/font_size" /> 


<TextView 
    android:id="@+id/textTimeToLine" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textTimer" 
    android:layout_centerHorizontal="true" 
    android:includeFontPadding="false" 
    android:text="10.02" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textSize="@dimen/font_size" /> 

<TextView 
    android:id="@+id/textTimeToKill" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textTimeToLine" 
    android:layout_centerHorizontal="true" 
    android:includeFontPadding="false" 
    android:text="10.03" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textSize="@dimen/font_size" /> 

<TextView 
    android:id="@+id/textTimeToPin" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textTimeToKill" 
    android:layout_centerHorizontal="true" 
    android:includeFontPadding="false" 
    android:text="10.03" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textSize="@dimen/font_size" /> 

<TextView 
    android:id="@+id/textTimeToCB" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textTimeToPin" 
    android:layout_centerHorizontal="true" 
    android:includeFontPadding="false" 
    android:text="10.03" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textSize="@dimen/font_size" /> 

    <Button 
    android:id="@+id/buttonMenu" 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:text="Menu" 
    android:onClick="onMenu" 
    android:focusable="false"/> 

</RelativeLayout> 

在這個屏幕截圖,你可以看到,喜歡的邊界或邊緣是我想要減少的區域。

Screen Shot

+0

更改字體大小是一個選項。一般而言,您需要上面一行之間的某種空間。以提高可讀性 – Doomsknight 2012-08-09 15:14:31

+0

填充控制文本距離視圖邊緣的距離。你試過把它設置爲0,它不起作用? – 2012-08-09 15:15:13

+0

@Atlos我將填充設置爲0,字體上方仍然有1/4英寸的填充。另外我有android:includeFontPadding =「false」。 – 2012-08-09 15:17:51

回答

4

一些負面的頂部和底部邊距。如果你有背景花色,事情會變得混亂。

+0

我不知道有多少次我以爲我嘗試過,但它的工作。謝謝。 \t \t android:layout_marginBottom =「 - 25sp」 android:layout_marginTop =「 - 25sp」 – 2012-08-09 17:45:32

0

使用在填充元件負值。

+2

那個我曾經嘗試過,它沒有任何東西。 – 2012-08-09 19:19:58

0

我覺得問題是由於padding/margin設置在textTimeToPin查看。如果您爲此視圖設置了任何間距,所以它將影響textTimeToCB的位置,因爲它設置爲在其下方顯示。

查看您的xml的周圍視圖或完全粘貼它,以便我們有更好的觀察。

+0

所有視圖都有android:includeFontPadding =「false」,並且與我發佈的視圖相同。這只是一個測試用例,除了名稱外,還有5個相同的視圖。我會發布整個XML。 – 2012-08-09 17:32:44

-1

您是否嘗試過這個?:

android:padding="5dp"