2010-11-19 7 views
1

AndroidのTableLayoutに行を追加しようとしていますが、orientationプロパティが機能していないようです。基本的には、TableRowを作成し、TextViewを複数追加し、TableLayoutに追加し、水平方向ではなく、垂直方向に積み重ねてTextViewを作成する必要があります。TableLayoutに垂直行を挿入する

XMLは次のようになります。

<TableLayout android:id="@+id/mylayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <TableRow android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
      <TextView android:text="Test1"></TextView> 
      <TextView android:text="Test2"></TextView> 
    </TableRow> 
</TableLayout> 

それが動作するはずのようにこれが見えますが、TextViewsは、左から右に積み重ねられてしまいます。何かご意見は?

答えて

0

は最後に挿入LinearLayoutのコントロールIDにハンドルを維持し、新しいを挿入しますそのIDの右側に1つ。ちょっとしたクルージングを感じますが、うまくいきます。

1

 <TextView android:text="Test1"></TextView> 
     <TextView android:text="Test2"></TextView> 

変更してみてください:

 <TextView android:text="Test1" android:layout_column="0"></TextView> 
     <TextView android:text="Test2" android:layout_column="0"></TextView> 

それは

細胞はカラム昇順で行を追加しなければならないと言うドキュメントTableLayouthttp://developer.android.com/reference/android/widget/TableLayout.html)を参照、両方コードとXMLで列番号はゼロベースです。子セルに列番号を指定しないと、次の使用可能な列に自動的にインクリメントされます。列番号をスキップすると、その行の空のセルとみなされます。 XMLでテーブルを作成する例については、ApiDemosのTableLayoutの例を参照してください。私はこのproblem.Iに対する解決策がRelativeLayoutを作り、私はプログラム的に各垂直row.Iのためにそれに垂直方向LinearLayoutを追加していた

+0

感謝をこののLinearLayoutを追加します。 layout_columnは、何かが見つからない限り、TextViewのプロパティではありません。私はこれを行うことによってプログラムで列を設定しようとしましたが、同じように見えます... TextView tv1 = new TextView(this); \t \t TextView tv2 =新しいTextView(this); \t \t tv1.setText( "Test1"); \t \t tv2.setText( "Test2"); \t \t tv1.setLayoutParams(new TableRow.LayoutParams(0)); \t \t tv2.setLayoutParams(new TableRow.LayoutParams(0)); – Nate

+0

あなたは入力ミスをしていないと肯定的ですか?ここで例を見ることができます:http://developer.android.com/resources/tutorials/views/hello-tablelayout.html – Thomas

+0

私はその例を見ました。列番号は機能しますが、データを水平に整理するためだけです。私は列が垂直に成長する必要があります。一度に1行ずつデータを上から下に追加しています。 – Nate

0

垂直方向のLinearLayoutを作成し、内部にテキストビューを作成します。そして、迅速な返信トーマスのためのTableRowに

<TableLayout android:id="@+id/mylayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <TableRow android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" > 
        <TextView android:text="Test1"></TextView> 
        <TextView android:text="Test2"></TextView> 
      </LinearLayout> 
    </TableRow> 
</TableLayout> 
+0

''と ''の利点は何ですか? –

1
We can do by inserting TableLayout inside TableRow,like this. 


<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TableLayout android:id="@+id/mylayout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 
     <TableRow android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
      <TableLayout android:id="@+id/mylayout1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical"> 
      <TextView android:text="Test1"></TextView> 
      <TextView android:text="Test2"></TextView> 
      </TableLayout> 
     </TableRow> 
    </TableLayout> 
    </LinearLayout> 
関連する問題