【发布时间】: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>
main.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
main.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