You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AutoCompleteTextView下拉列表每一项下方重复其他控件问题求助

问题根因

你遇到的异常是AutoCompleteTextView下拉列表背景透明 + 根布局高度配置错误共同导致的:

  • 你当前的根LinearLayout设置了android:layout_height="wrap_content",AutoComplete的下拉弹窗默认依附于控件下方绘制时,会复用父布局的绘制缓存,导致下层的EditText被重复绘制到下拉列表区域
  • AutoCompleteTextView没有显式设置不透明的下拉背景,下拉区域默认透明,直接透出下层控件的绘制内容

解决方案

按以下步骤修改即可修复:

  1. 将根布局的android:layout_height属性从wrap_content修改为match_parent,避免父布局绘制缓存被下拉弹窗异常复用
  2. 给AutoCompleteTextView添加android:dropDownBackground属性,设置不透明的下拉背景,阻断下层控件透出
  3. 确保给AutoCompleteTextView绑定Adapter时,显式指定标准的下拉项布局,不要使用自定义的含其他控件的布局

修改后的布局参考代码

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:background="@color/window_background"
    android:visibility="visible">
    <LinearLayout
        android:id="@+id/ll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <AutoCompleteTextView
            android:id="@+id/recipientName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:completionThreshold="0"
            android:padding="10dp"
            android:textColor="#000"
            android:textSize="16sp"
            android:dropDownBackground="@android:drawable/spinner_dropdown_background" />

    </LinearLayout>
    <EditText
        android:id="@+id/messageText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20sp"
        android:background="@color/Plum"
        android:gravity="top|start"
        android:autofillHints="test"
        android:lines="10"
        android:inputType="text"
        android:padding="20sp"
        android:textColor="@color/Black"           />
</LinearLayout>

补充说明

如果修改后还有异常,可以额外给AutoCompleteTextView添加android:dropDownHeight="wrap_content"属性,限制下拉列表的最大高度,避免绘制区域溢出。

内容的提问来源于stack exchange,提问作者Netnoob

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 18:45:03