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>
开发者_JAVA百科
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.
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;
You can use "android:weightSum" on your <TableRow>
to adjust the width fixed on the screen.
Example :
<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>
By this code your spinner width will be set as half the width of your TableRow.
Change the values of android:weightSum and android:layout_weight as per your requirement.
精彩评论