首页 > 解决方案 > AutoCompleteTextView 设置高度以填充父级

问题描述

我是 Android 开发的新手,自己学习!我只想将我的 AutoCompleteTextView 下拉高度设置为填充父级。


我在 XML 中的 AutoCompleteTextView 视图是:

  <AutoCompleteTextView
    android:id="@+id/countries_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="@dimen/_20sdp"
    android:dropDownHeight="match_parent"
    android:ems="10">
</AutoCompleteTextView>

我还附上了一个屏幕截图,显示下拉列表的绿色部分仅填充父项的一部分,但我希望它按其高度填充父项。不知道有没有可能?有人能找出我的可能性吗?


DropDown 不按其高度填充父级


有关额外信息,我将在此处添加完整的布局:

 <?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context=".MainActivity">

    <AutoCompleteTextView
        android:id="@+id/countries_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/_20sdp"
        android:dropDownHeight="match_parent"
        android:ems="10">
    </AutoCompleteTextView>

    <RelativeLayout
        android:id="@+id/revealLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="?android:attr/actionBarSize"
        android:animateLayoutChanges="true"
        android:background="#00FFA9"
        android:visibility="gone">

        <TextView
            android:id="@+id/textReveal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="Hello Reveal!"
            android:textColor="#000000"
            android:textSize="@dimen/_24ssp"/>
    </RelativeLayout>
</RelativeLayout>

标签: androiddropdownautocompletetextview

解决方案


如果您正在使用,android:dropDownHeight="match_parent"那么它将在 API 8 之后工作,而不是更少。除非您输入固定值,例如 200dp 或 300dp。


推荐阅读