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 spinner根据数据改变其宽度。我想阻止它。

谁能指导我如何实现这一目标?

任何帮助都会得到帮助。

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