【问题标题】:AutoCompleteTextView dropDown height is incorrectAutoCompleteTextView dropDown 高度不正确
【发布时间】:2018-03-06 23:17:05
【问题描述】:

我正在使用 AutoCompleteTextView 和自定义 item_layout。如果layout_width 不是match_parent,则会显示滚动条,即使提示太大时我只有一个提示。但是如果我们使用宽度match_parent,则没有滚动条。我想为AutoCompleteTextView 锚使用有限的宽度,而不需要那个烦人的滚动。 这是代码。

item_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:minHeight="48dp">

    <TextView
        android:id="@+id/autocomplete_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:gravity="center_vertical"
        android:includeFontPadding="false"
        android:paddingLeft="12dp" />

</LinearLayout>

ma​​in.xml 宽度有限(例如 200dp)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/anchor"
    android:layout_width="200dp"
    android:layout_height="wrap_content">

    <AutoCompleteTextView
        android:id="@+id/auto_complete"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:completionThreshold="1"
        android:dropDownAnchor="@id/anchor"/>
</LinearLayout>

Result with limited width of anchor

ma​​in.xml width=match_parent

<LinearLayout
    android:id="@+id/anchor"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <AutoCompleteTextView
        android:id="@+id/auto_complete"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:completionThreshold="1"
        android:dropDownAnchor="@id/anchor"/>
</LinearLayout>

Result with width="match_parent" anchor parameter no scrollBar!

【问题讨论】:

    标签: android listview autocompletetextview android-popupwindow


    【解决方案1】:
    <AutoCompleteTextView
    android:id="@+id/autocomplete_dogs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/Autocomplete"
    android:hint="Search dogs..."
    android:dropDownAnchor="@+id/header"
    android:dropDownWidth="match_parent"
    />
    

    这里是完整指南AutocompleteTextView

    【讨论】:

    • 我不想使用比锚点更大的 DropDown 宽度。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    • 1970-01-01
    • 2023-02-01
    • 2018-08-26
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多