0

Android の 2 列のテーブルでスピナーを右揃えにしようとしています。

これは私がこれまでに試したことです:

<TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/object_background">

        <TableRow>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Test"/>

            <Spinner
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:gravity="right"/>
        </TableRow>
4

2 に答える 2

1

1) textView コンポーネントで and を使用しandroid:layout_width="0dp"ますandroid:layout_weight="1"

2) android:layout_width="match_parent"tableRow に設定します。

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Test" />

        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </TableRow>
</TableLayout>

出力:

ここに画像の説明を入力

于 2014-11-02T08:34:07.960 に答える
0

これがテーブルで機能するかどうかはわかりませんが、左/右の重力でウェイトを使用してみることができます (ただし、ネストされたウェイトがパフォーマンスに悪いという警告が表示されます)。線形レイアウト:

<TextView
            android:id="@+id/TextViewID"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_weight="0.4"
            android:text="@string/TextView" />

        <Spinner
            android:id="@+id/SpinnerID"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="0.6" />

上記は、Spinner を Text View の右側に揃えます

于 2014-01-29T21:35:56.863 に答える