如何强制AutoCompleteTextView下拉元素折行为三行或更多行?

3
我无法强制AutoCompleteTextView下拉元素在三行或更多行中换行。
如您所见:
下拉菜单未选中前:drop-down before selection 下拉菜单选中后:drop-down after selection 第一张图片(下拉元素)中的文本消失了,但我希望它能够换行成更多行。
编辑:这是我的下拉项xml代码。
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/dropDownItemStyle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="false"
    android:lines="4"
    android:minLines="4"
    android:textSize="10sp"/>

我该怎么做?

你试过改变minLines属性吗? - meh
将android:layout_height设置为"wrap_content" - Mehul Ranpara
@Mehul1000 我试过设置 android:layout_height="wrap_content" 但它不起作用... 仍然只有一行 - wildnove
更好的答案: https://dev59.com/WHE95IYBdhLWcg3wft5w#7880441 - Maxim
2个回答

2
解决了! 我的布局dropdown_multiline_item.xml代码变成了:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/textContainer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:lines="3"
        android:gravity="center_vertical"
        android:padding="5dp"
        android:textColor="#000"
        android:textSize="10sp" />

</LinearLayout>

秘密在于这两种方法(进入适配器):

[...]

@Override
public void bindView(View view, Context context, Cursor cursor) {
    final String text = convertToString(cursor);
    ((TextView) view.findViewById(R.id.textContainer)).setText(text);
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    final LayoutInflater inflater = LayoutInflater.from(context);
    final View view = inflater.inflate(R.layout.dropdown_multiline_item, parent, false);
    return view;
}

[...]

希望这能帮助到某个人


0

将一个TextView定义为XML布局,并设置所有需要的属性使其显示正确(如lines、ellipsize、maxLines、minLines等)。然后使用android:completionHintView属性将下拉菜单设置为显示您定义的TextView。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接