2010-11-04 86 views
2

我不明白爲什麼我需要做的是讓我的視圖在TableLayout中完美對齊。爲什麼這些意見不一致?

我有一個類似的佈局:

<TableLayout android:id="@+id/keyboard" 
    android:layout_width="fill_parent" 
    android:layout_height="378px"> 
    <TableRow android:layout_span="5" > 
     <TextView android:id="@+id/button20" 
      android:layout_width="63px" 
      android:layout_height="42px" 
      android:textSize="10" 
      android:text="L1" /> 
     <TextView android:id="@+id/button21" 
      android:layout_width="63px" 
      android:layout_height="42px" 
      android:textSize="12" 
      android:text="L2" /> 
     <TextView android:id="@+id/button22" 
      android:layout_width="63px" 
      android:layout_height="42px" 
      android:textSize="12" 
      android:text="L3" /> 
     <TextView android:id="@+id/button23" 
      android:layout_width="63px" 
      android:layout_height="42px" 
      android:textSize="12" 
      android:text="L4" /> 
     <TextView android:id="@+id/button24" 
      android:layout_width="63px" 
      android:layout_height="42px" 
      android:textSize="12" 
      android:text="L5" /> 
    </TableRow> 
</TableLayout> 

現在,當畫,第一TextView的顯示2個像素比所有其他的人。 覆蓋onLayout方法;我看到onLayout被稱爲第一個查看: top = 2;底部= 44;而所有其他的都是top = 0;底部= 42.

只要字體大小與其他字體大小不同,就會發生這種情況;或者如果文本換行在另一行(因爲它不符合寬度)。 所有TextView具有相同的尺寸;但有些顯示比另一個略低。

這種佈局是一個RelativeLayout的範圍內,如果有差別。

我嘗試了很多不同的組合,而且總是有一些差異發生。 任何幫助將不勝感激。

謝謝! JY

回答

3

它看起來像的是在他們的基線對齊TextView的。因此,如果文字較小,則它的基線在文本視圖中會更高。因此,文本視圖的位置會更低,以便與其他文本查看的基線相匹配,文本查看更高。

爲了防止行基線對齊,儘量到的TableRow行更改爲:

<TableRow android:layout_span="5" android:baselineAligned="false" > 

缺點當然是文本可能看起來不對準了的。

+1

謝謝你,謝謝你,謝謝你...太專注於每個視圖的大小比我以前沒有注意到的是,文本的基線對齊所有從...時間 – jyavenard 2010-11-04 23:35:57

+0

古答案自古以來,但仍有關! – 2016-01-26 20:13:52