2013-01-16 281 views
0

我想弄清楚如何對齊dashboardNewsItemDate而不是在左邊。目前它立即顯示在dashboardNewsItemHeadline旁邊。我認爲把它放在TableRow之內會使我的android:layout_gravity="right"函數,但這被證明是錯誤的。如何對齊文本到右側

<TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:layout_gravity="center"> 
    <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
     <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="New Text" 
       android:id="@+id/dashboardNewsItemHeadline" android:layout_gravity="left" 
       /> 
     <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="New Text" 
       android:id="@+id/dashboardNewsItemDate" android:layout_gravity="right" android:autoText="false"/> 
    </TableRow> 
</TableLayout> 

最終,我的目標是爲內容,所以顯示是這樣的...

My news title      Mar 3 
----------------------------------------- 
This is a bit of a longer news  Jul 2 
title and it wraps 

回答

0

你靠近,嘗試定期 「萬有引力」,而不是您的TextView的「layout_gravity」。

+0

不幸的是,沒有工作: - \ – Webnet

0

上一個TextView中的layout_width="wrap_content"取消了gravity="right"。將其更改爲fill_parentmatch_parent,它應該可以工作。

0

有一種神奇的屬性,它應該解決您的問題:

android:stretchColumns="*" 

這個屬性添加到您的TableLayout

<TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" 
     android:stretchColumns="*"> 
    <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
     <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="New Text" 
       android:id="@+id/dashboardNewsItemHeadline" android:layout_gravity="left" 
       /> 
     <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="New Text" 
       android:id="@+id/dashboardNewsItemDate" android:layout_gravity="right" android:autoText="false"/> 
    </TableRow> 
</TableLayout>