5

这是我的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
          android:layout_width="fill_parent" android:id="@+id/LinearLayout01"
         android:layout_height="wrap_content">

    <Spinner android:text="@+id/AutoCompleteTextView01"
                       android:id="@+id/Spinner01"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:width="130dp"></Spinner>
    <EditText android:layout_height="wrap_content"
              android:layout_width="wrap_content"
             android:id="@+id/Chapter" android:width="30dp"></EditText>
    <TextView android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/TextView01" android:text=":"></TextView>
    <EditText android:layout_height="wrap_content"
              android:layout_width="wrap_content" android:id="@+id/Verse"
              android:width="40dp"></EditText>

</LinearLayout>

我将此布局膨胀为 AlertDialog 的视图。但是当我选择一个大元素时,文本字段会被推到右侧。有没有办法设置微调器的最大尺寸,所以在选择一个元素后,它会用省略号(“...”)或其他东西缩短选择?

4

3 回答 3

5

No need to use a custom adapter. Use the android.R.layout.simple_spinner_item and then change it from ellipse marquee to end ellipse. Then set your new change layout file as layout id or use this layout file

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingRight="10dp"
    android:ellipsize="end" />
于 2013-07-23T12:38:25.260 回答
4

Spinner集合的大小android:layout_width="wrap_content"由其内容决定。如果你想要椭圆的东西,那SpinnerAdapter在你创建行视图时由你决定。

或者,硬连线一个android:layout_width尺寸固定的。

或者,不是使用 ,而是LinearLayout使用RelativeLayout和构建规则,以便Spinner通过将其锚定到屏幕的左侧和第一个 的左侧来占用行上的剩余空间EditText。虽然我不能 100% 确定如果内容太大会发生什么——它可能只是被截断了。

于 2010-03-05T23:40:43.973 回答
1

设置 spinner android:background="@null"来解决问题。这也将隐藏下拉图标的可见性

于 2019-09-20T09:26:45.043 回答