4

私が達成したいことは次のとおりです。テーブル行がたくさんあるテーブルがあります。各行には、製品のタイトルとサブタイトルを重ねた 2 つのテキスト ビューが必要です (サブタイトルはまだ実装されていません)。は左揃えにする必要があります。右側では、スピナーで数量を選択します。

テキストはデータベースから取得され、もちろん長さが異なります。

これが私がこれまでに思いついたものです:

<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>

スクリーンダンプ:

ここに画像の説明を入力

最初の問題は、RelativeLayout がテーブル行の幅を埋めていないことです。2 つ目の問題: スピナーが正しく配置されていません。

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

よろしくアラン

4

3 に答える 3

4

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

この行を ScollView 属性に追加すれば完了です :)

于 2015-08-16T16:45:02.840 に答える
2

android:layout_weight="1"あなたのrelativelayoutに追加

于 2016-07-15T16:11:51.670 に答える
2

もっとシンプルに、もっと軽くしたい。RelativeLayoutこれら4つのビューすべてに使用してください。両方のスピナーを右に揃えてテキストビューを作成し、相対スピナーmatch_parentを追加します。toLeftOf欲しいものが見えると思います。

于 2012-04-24T02:03:50.187 に答える