spinner expanding beyond screen bounds
I have a layout that contains a TableLayout with three rows. Each row has a TextView and a Spinner. The Spinners' column is set to stretch. My problem is that the Spinners are stretching off the edge of the screen when they contain a long string. I would like them to truncate the string instead. Here's a screenshot of the problem:
http://www.comicfanboy.net/images/screenshot.png
and here's the xml for the layout:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/settings_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal">
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:paddingLeft="3dp" android:paddingRight="3dp">
<TextView android:id="@+id/textView1" android:layout_height="wrap_content" android:text="@string/general_information_defaults" android:gravity="center_horizontal" android:layout_width="fill_parent"></TextView>
<TableLayout android:layout_height="wrap_content" android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:stretchColumns="1">
<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/textView2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="right|center_vertical" android:text="Spinner Label 1"></TextView>
<Spinner android:layout_height="wrap_content" android:id="@+id/default_organization_spinner" android:layout_width="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/TextView01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="right|center_vertical" android:text="Spinner Label 2"></TextView>
<Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/default_sport_spinner"></Spinner>
</TableRow>
<TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/TextView02" android:gravity="right|center_vertical" android:layout_height="fill_parent" android:layout_width="fill_parent" android:text="Spinner Label 3"></TextView>
<Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/default_injury_spinner"></Spinner>
</TableRow>
</TableLayout>
<TextView android:layout_width="fill_parent" android:id="@+id/TextView03" android:gravity="center_horizontal" android:layout_height="wrap_content" android:text="@string/email_defaults" android:paddingTop="20dp"></TextView>
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/TableLayout01" android:stretchColumns="1">
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/TableRow02">
<TextView android:layout_height="fill_parent" android:id="@+id/TextView04" android:gravity="right|center_vertical" android:layout_width="fill_parent" android:text="@string/to"></TextView>
<EditText android:inputType="textEmailAddress" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/default_to_field">
<requestFocus></requestFocus>
</EditText>
</TableRow>
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/TableRow01">
<TextView android:layout_height="fill_parent" android:id="@+id/TextView06" android:gravity="right|center_vertical" android:layout_width="fill_parent" android:text="@string/cc"></TextView>
<EditText android:inputType="textEmailAddress" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/default_cc_field"></EditText>
开发者_运维问答 </TableRow>
</TableLayout>
<TextView android:layout_width="fill_parent" android:id="@+id/TextView05" android:gravity="center_horizontal" android:layout_height="wrap_content" android:text="@string/program_options" android:paddingTop="20dp"></TextView>
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingLeft="40dp" android:id="@+id/auto_sync_checkbox" android:text="@string/auto_sync_at_login"></CheckBox>
</LinearLayout>
</ScrollView>
For the spinner:
android:layout_weight="1"
This helped me.
android:layout_width="100dip"
Use this tag in the spinner.
精彩评论