2012-04-24 12 views
4

ここでは達成したいことがあります: テーブルの行がたくさんあります。各行には、商品のタイトルとサブタイトルが上に並んだ2つのテキストビューが必要です(サブタイトルはまだ実装されていません)。左揃えにする必要があります。右側にはスピナーが数量を選択します。MATCH_PARENTを使用したRelativeLayoutは機能しません

テキストはデータベースから来たもので、もちろん長さは異なります。ここで

は、私がこれまでに作ってみたものです:

<ScrollView android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1"> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/barmenu" 
     android:background="#99ffff" 
     android:scrollbars="vertical"> 

     <TableRow 
     android:layout_height="wrap_content" 
     android:background="#ffff99" 
     android:layout_width="match_parent"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:background="#0000ff"> 

      <TextView 
       android:id="@+id/productTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="#88ffff" 
       android:ellipsize="end" 
       android:padding="2dp" 
       android:singleLine="true" 
       android:text="Product name" 
       android:textColor="#000000" 
       android:gravity="left" 
       android:textSize="13sp" 
       android:textStyle="bold" /> 

      <Spinner 
       android:gravity="right" 
       android:layout_height="40dp" 
       android:layout_toRightOf="@id/productTitle" 
       android:width="100dp" 
       android:layout_width="wrap_content" /> 
     </RelativeLayout> 
     </TableRow> 
     <TableRow 
     android:layout_height="wrap_content" 
     android:background="#ffff99" 
     android:layout_width="match_parent"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:background="#0000ff"> 

      <TextView 
       android:id="@+id/productTitle2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="#88ffff" 
       android:ellipsize="end" 
       android:padding="2dp" 
       android:singleLine="true" 
       android:text="Some long long long long name" 
       android:textColor="#000000" 
       android:gravity="left" 
       android:textSize="13sp" 
       android:textStyle="bold" /> 

      <Spinner 
       android:gravity="right" 
       android:layout_height="40dp" 
       android:layout_toRightOf="@id/productTitle2" 
       android:width="100dp" 
       android:layout_width="wrap_content" /> 
     </RelativeLayout> 
     </TableRow> 
    </TableLayout> 
</ScrollView> 

スクリーンダンプ:

enter image description here

まず問題はRelativeLayoutは、テーブルの幅を記入していないということです行。そして2番目の問題:スピナーは正しく整列していません。

私には何が欠けていますか?

よろしく アラン

答えて

2

私はそれが簡単かつ軽量化と思います。これらの4つのビューすべてにRelativeLayoutを使用してください。両方のスピナーを右に揃え、テキストビューを-とし、toLeftOfに相対スピナーを追加します。私はあなたが望むものが見えると思う。

+0

android:layout_weight="1"を追加します:)終わっ...私の例のようにTableRowごとに1つのRelativeLayoutを意味しますか? – allanth

+0

いいえ、私はRelativeLayoutを意味し、テーブルは全くありません。 –

4

アンドロイド:fillViewport = "true" の

あなたScollView属性に次の行を追加し、あなたが

2

はちょうどそれを明確にするためにあなたのrelativelayout

関連する問題