我使用以下代码自动完成,但是,下拉项出现在AutoCompleteTextView
之上。我想让它显示在AutoCompleteTextView
下面。我该怎么做呢?
package com.example.autocomplete;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium","Belgam","Bellam", "France Belgium", "Italy", "Germany", "Spain"
};
}
xml:
<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="${relativePackage}.${activityClass}" >
<AutoCompleteTextView
android:id="@+id/countries_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:dropDownHeight="100dp"
android:ems="10"
android:text="AutoCompleteTextView" >
<requestFocus />
</AutoCompleteTextView>
</RelativeLayout>
发布于 2015-09-14 20:08:23
设置dropdown的高度,并设置dropdown和edittext之间的间距。Dropdown将在dropdownanchor中显示视图的上方和下方。高度= 200dp,下拉框不会与键盘重叠。
<RelativeLayout
android:id="@+id/dropdownAutoCompleteTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingTop="8dp">
<AutoCompleteTextView
android:id="@+id/autoTextViewState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:digits="@string/get_started_petname_digits"
android:dropDownAnchor="@+id/dropdownAutoCompleteTextView"
android:dropDownHeight="200dp"
android:hint="Colorado"
android:imeOptions="actionNext"
android:inputType="textEmailAddress|textCapWords"
android:maxLength="15"
android:nextFocusDown="@+id/editZipCode"/>
</RelativeLayout>
发布于 2016-04-13 19:30:09
在您的布局中使用AutoCompleteTextView
上的android:dropDownAnchor
、android:dropDownHorizontalOffset
、android:dropDownVerticalOffset
等。有关更多信息,请访问AutocompleteTextView。
发布于 2017-07-27 20:33:00
加上dropdownheight以及dropdownanchor,肯定会起作用。
android:dropDownAnchor="@id/yourIdOfViewOnTop"
android:dropDownHeight="100dp"
https://stackoverflow.com/questions/26401412
复制相似问题