【问题标题】:How to force AutoCompleteTextView drop down elements to wrap text in three or more lines?如何强制 AutoCompleteTextView 下拉元素将文本包装成三行或更多行?
【发布时间】:2013-01-17 20:16:22
【问题描述】:

我无法强制 AutoCompleteTextView 下拉元素将文本换成三行或更多行。

如你所见:

第一张图片(下拉元素)中的文字消失了,但我不希望它换行。

已编辑:这是我的下拉项的 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 属性吗?
  • 设置 android:layout_height ="wrap_content"
  • @Mehul1000 我试图设置 android:layout_height ="wrap_content" 但它不起作用...窗台只有一行

标签: android autocompletetextview


【解决方案1】:

解决了! 我的布局 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;
}

[...]

希望这会对某人有所帮助

【讨论】:

    【解决方案2】:

    将 TextView 定义为 XML 布局,其中包含使它看起来正确所需的所有属性(lines、ellipsize、maxLines、minLines 等)。使用android:completionHintView 属性设置下拉菜单以显示您定义的文本视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-03
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多