2012-07-03 32 views
-1

我想創建2行3列的表格佈局, 第一行我想添加3個TextView,第二行我想在三列上添加一個按鈕。如何在Android TableLayout中製作可擴展的TextViews?

每個文本視圖都會填充其他點擊操作的文本,所以它可能包含100個字符並且可能不包含字符 因此,如果第一個字符有字符而其他字符沒有,則第一個字符應該擴展爲覆蓋所有的空間,但如果兩個包含文本,這兩個應該擴大到填補空的空間

誰能幫助我? 這是我的代碼,但是這個代碼不正確的,它把表分成三等於列

<TableLayout 
     android:id="@+id/temps_holder" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/google_adView" 
     android:background="@drawable/round" 
     android:gravity="right"   
     android:stretchColumns="0" > 

     <TableRow> 

      <TextView 
       android:id="@+id/time_temp" 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_marginLeft="3dp" 
       android:layout_marginRight="3dp" 
       android:layout_weight=".33" 
       android:gravity="center" 
       android:singleLine="false" 
       android:text="" 
       android:textColor="@color/White" 
       android:textSize="16sp" /> 

      <TextView 
       android:id="@+id/tempText2_TextView" 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_weight=".33" 
       android:gravity="center" 
       android:singleLine="false" 
       android:text="" 
       android:textColor="@color/White" 
       android:textSize="16sp" /> 

      <TextView 
       android:id="@+id/tempText1_TextView" 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_weight=".33" 
       android:gravity="center" 
       android:singleLine="false" 
       android:text="" 
       android:textColor="@color/White" 
       android:textSize="16sp" /> 
     </TableRow> 

     <TableRow> 

      <Button 
       android:id="@+id/viewMatched_btn" 
       android:layout_width="fill_parent" 
       android:layout_height="40dp"     
       android:layout_span="3" 
       android:background="@drawable/wood_btn" 
       android:onClick="viewResults" 
       android:text="@string/viewMatched" 
       android:textColor="@color/White" 
       android:visibility="invisible" /> 
     </TableRow> 
    </TableLayout> 

回答

0

這是你所追求的?

<TableRow> 

     <Button 
      android:id="@+id/viewMatched_btn" 
      android:layout_width="fill_parent" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button"    
      android:onClick="viewResults"    
      android:visibility="visible" /> 
    </TableRow> 
</TableLayout> 

更改按鈕屬性:android:visibilityvisible並添加:

android:layout_width="wrap_content" android:layout_height="wrap_content"

enter image description here

enter image description here

enter image description here

+0

此源代碼是來自大文件的代碼的子代,我在原始文件中使用了xmlns –

+0

O我明白了,對不起。我會更新我的答案。 – 0gravity

+0

您是否爲每個文本視圖測試了超過100個字符? –

相關問題