如何阻止我的 AutoCompleteTextView 下拉菜单在我的 AutoCompleteTextView 上滚动?

How do I stop my AutoCompleteTextView dropdown from scrolling over my AutoCompleteTextView?

我有一个 AppCompatAutoCompleteTextView,其锚点比 AppCompatAutoCompleteTextView 更靠下。这是设计使然,无法更改。当我在下拉菜单上滚动时,下拉菜单向上移动并位于 AppCompatAutoCompleteTextView.

的顶部

它应该这样工作吗?

这是我的代码:

主要activityxml:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.autocompletetest.MainActivity">
    <android.support.v7.widget.AppCompatAutoCompleteTextView
        android:id="@+id/autocomplete"
        android:layout_width="match_parent"
        android:layout_height="32dp"

        android:layout_gravity="center"
        android:layout_marginLeft="8dp"
        android:layout_weight="1"
        android:alpha="0.87"
        android:background="#ffffff"
        android:dropDownWidth="match_parent"
        android:dropDownAnchor="@+id/anchor"
        android:gravity="center_vertical"

        android:hint="entervalue"
        android:inputType="textUri"
        android:popupBackground="@null"
        android:selectAllOnFocus="true"
        android:singleLine="true"
        android:textColor="#000000"
        android:textSize="14sp"
        android:layout_alignParentTop="true"
        android:textColorHint="#000000"
        />
    <View
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:layout_marginTop="3dp"
        android:layout_below="@+id/autocomplete"
        android:id="@+id/anchor"
        android:background="#aaaaaa"/>
</RelativeLayout>

主要activityjava:

AppCompatAutoCompleteTextView auto = (AppCompatAutoCompleteTextView) findViewById(R.id.autocomplete);
        String[] countries = getResources().getStringArray(R.array.colors);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,countries);
        auto.setAdapter(adapter);

编辑:我应该提到我在 Marshmallow 上看到了这种行为。

根据文档,它说:

View to anchor the auto-complete dropdown to. If not specified, the text view itself is used.

您是否需要自定义锚点?我想默认情况下没有这种行为可能是由您的相对布局引起的。

问题的发生似乎是因为 android:popupBackground="@null"

删除 --> android:popupBackground="@null"
来自 AutoCompleteTextView

然后检查它。