2011-10-08 48 views
1

我想在我的應用程序中實現這種類型的視圖。 。 。如何在android中設置這個tableLayout?

data1 hello hi 
data2 hello2 hi 
data3 hi  Hello 

我想知道,哪一個是設置它的最好方法? TableLayout oranyother linearLayout.RelativeLayout ??? 我也想要xml代碼來設置這個佈局。 。 謝謝。

回答

4

試試這個,

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TableLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <TableRow android:weightSum="3"> 
      <TextView android:layout_weight="1" android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:text="hello" /> 
      <TextView android:layout_weight="1" android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:text="hello" /> 
      <TextView android:layout_weight="1" android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:text="hello" /> 
     </TableRow> 

     <TableRow android:weightSum="3"> 
      <TextView android:layout_weight="1" android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:text="hello" /> 
      <TextView android:layout_weight="1" android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:text="hello" /> 
      <TextView android:layout_weight="1" android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:text="hello" /> 
     </TableRow> 

     <TableRow android:weightSum="3"> 
      <TextView android:layout_weight="1" android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:text="hello" /> 
      <TextView android:layout_weight="1" android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:text="hello" /> 
      <TextView android:layout_weight="1" android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:text="hello" /> 
     </TableRow> 
    </TableLayout> 
</LinearLayout> 
+1

好的不錯。有用。現在,如果我想給更多大小的第二列,那麼我應該把weightSum給4,第二個textview權重2吧? –

+0

是的,我認爲你知道它是如何工作的。 :) –

+0

是的,我明白了。謝謝。 –

2

TableLayout是可取的是你的情況。 例如:http://www.tutorialforandroid.com/2008/12/simple-tablelayout-in-android.html

@note:只是不要這麼懶得Google!

+0

親愛的我已經在谷歌搜索。但我想要這樣的佈局,以適應屏幕的寬度。佈局應該是出色的。這就是爲什麼我提出了問題。我仍然沒有得到正確的答案。因爲我想要適合設備屏幕的佈局。 –

+0

設置'fill_parent'來填充整個屏幕的佈局 –

相關問題