ここでは達成したいことがあります: テーブルの行がたくさんあります。各行には、商品のタイトルとサブタイトルが上に並んだ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>
スクリーンダンプ:
まず問題はRelativeLayoutは、テーブルの幅を記入していないということです行。そして2番目の問題:スピナーは正しく整列していません。
私には何が欠けていますか?
よろしく アラン
に
android:layout_weight="1"
を追加します:)終わっ...私の例のようにTableRowごとに1つのRelativeLayoutを意味しますか? – allanthいいえ、私はRelativeLayoutを意味し、テーブルは全くありません。 –