spinner expanding beyond screen bounds

ぐ巨炮叔叔 提交于 2019-12-04 05:27:38

问题


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>

回答1:


android:layout_width="100dip" Use this tag in the spinner.




回答2:


For the spinner:

android:layout_weight="1"


This helped me.



来源:https://stackoverflow.com/questions/6543539/spinner-expanding-beyond-screen-bounds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!