2

以下のレイアウトを作成しました。

<TableLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:orientation="horizontal"
        >
        <TableRow>


<TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="Post As" />


<Spinner 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/ddlPostAs"
        />
        </TableRow>
        <TableRow>
<TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="Expires In" />

<Spinner 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/ddlExpiryOn"

        />
</TableRow>
</TableLayout>

Androidスピナーはデータに応じて幅を変更します。やめたい。

誰かがこれを達成する方法を教えてもらえますか?

どんな助けでも適用されるでしょう。

4

2 に答える 2

5

画面の幅に合わせて幅を固定します。

 DisplayMetrics d = new DisplayMetrics(); 
 getWindow().getWindowManager().getDefaultDisplay().getMetrics(d); 
 int wdt = d.widthPixels;
 ddlpostas.getLayoutParams().width = wdt - 120;
 ddlexpiryon.getLayoutParams().width = wdt - 120;
于 2010-05-31T06:48:50.927 に答える
2

「android:weightSum」を使用<TableRow>して、画面に固定された幅を調整できます。

例 :

<TableRow android:weightSum="2">

            <TextView android:layout_width="0dp"
                android:layout_gravity="center_vertical"
                android:layout_height="wrap_content" android:text="Post As"
                android:layout_weight="1"/>

            <Spinner
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/ddlPostAs"
                android:layout_weight="1"
                />
        </TableRow>

このコードにより、スピナーの幅は TableRow の幅の半分に設定されます。

要件に応じて android:weightSum と android:layout_weight の値を変更します。

于 2016-07-13T11:59:45.097 に答える