UMAR UMAR - 1 year ago 164
Android Question

android spinner width problem?

i have created following layout.

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


in which android spinner changes its width according to the data.
i want to stop it.

can any one guide me how to achieve this?

any help would be appriciated.

Answer Source

By fixing the width according to the width of screen.

 DisplayMetrics d = new DisplayMetrics(); 
 getWindow().getWindowManager().getDefaultDisplay().getMetrics(d); 
 int wdt = d.widthPixels;
 ddlpostas.getLayoutParams().width = wdt - 120;
 ddlexpiryon.getLayoutParams().width = wdt - 120;