2012-04-05 12 views
0

私のアプリケーションでは、プログラムでTableViewを構築しています。表は、5つのテキストビューで次の行にまたがる長いテキスト(画面幅の約80%)を通常含むテキストビューの一連の単一行を使用します。これはうまくいきましたが、残念ながら、これらの行に1つのテキストボックスでチェックボックスを入れる必要があります。テキストボックスの内容の長さのために、このチェックボックスは右側に配置され、可能な幅がより小さくなります。しかし、テキストボックスを4列だけに広げて、5列目に予約されたスペースにチェックボックスを置くと、チェックボックスの幅が広すぎるため、テキストが十分ではありません。この状況を示す例を用意しました。表形式のレイアウトで列番号と幅の制限を上書きする方法はありますか?

+---------------------------------------------------+ 
|TextView spanning over 5 columns below    | <- 1 column spans over 5 
|-----+------+---------------+------+---------------| 
|col1 | col2 |Column number 3| Col4 | Column number5| <- 5 columns 
|-----+------+---------------+------+---------------| 
|This spans over 4 column - not enou|[V]   | 
|gh         |    | <- 2 columns, 1st spans over 4 
|-----+------+---------------+------+---------------| 
|col1 | col2 |Column number 3| Col4 | Column number5| <- 5 columns 
|-----+------+---------------+------+---------------| 
|This is what I need-checkbox maximum to right |[V]| <- 2 columns 
+---------------------------------------------------+ 

最後の行は、私がそれを見せるために必要なものを示しています。 HTMLでは、行の内側に別のテーブルを入れ子にし、それに応じてこの新しいテーブル内に幅を分割しますが、このシナリオはAndroid TableLayoutで構築できないようです。

これを達成する方法を知っている人はいますか?

答えて

0

もう一度試してください;) 変更はテーブルレイアウトのプロパティ、2番目の行のテキストビュー、およびチェックボックスのlayout_gravityにあります。私は、この要素を使用すると、プログラムで同じことを行うことができるようになりますと仮定;)

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:stretchColumns="0,1,2,3" > 

    <TableRow 
     android:id="@+id/tableRow" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:text="@string/app_name" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:text="@string/app_name" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:text="@string/app_name" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:text="@string/app_name" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:text="@string/app_name" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_span="4" 
      android:text="@string/app_name" /> 

     <CheckBox 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" /> 
    </TableRow> 

</TableLayout> 

がアンドロイドを見て:shrinkColumnsとAndroid:あなたのテーブルのstretchColumnsプロパティを。

setColumnShrinkable(int columnIndex, boolean isShrinkable) 
setColumnStretchable(int columnIndex, boolean isStretchable) 

この方法を使用すると効果があります(テストしていません)。

+0

私は同様のアイデアを持ち、私が望んだ通りに見えるXMLレイアウトを構築します。しかし、XMLでうまく動作するこのネストされたLineraLayoutに "span"属性を追加する必要がありますが、プログラムで追加する方法はわかりません(このパラメータはLinearLayoutでは無効です)... – Krecik2002

+0

フィリップ主な問題は、列の幅が正確に一致しない場合、この2列の行を5列の行に結合することです。 – Krecik2002

+0

さて、私はこれを初めて理解しませんでした。今見えにくいです;) 5番目の行の大きさはどれくらいありますか?あなたが収縮可能に設定した場合、それは小さすぎるでしょうか? – Philippe

関連する問題