我有一个自定义的AutoCompleteTextView。当我在列表中有多个结果时,上下文列表显示在AutoCompleteTextView上方,但当它缩小答案为1时,上下文列表被移动,因此它位于AutoCompleteTextView下面,这是我的情况下将它放在软键盘下面,这样你就可以看到结果。
以下是列表中有2个项目的示例。
此处结果已移至:
我知道列表就在那里所以不是因为没有结果。 那么有没有办法强制列表显示在AutoCompleteTextView上方?
答案 0 :(得分:1)
我找到了办法。
对于某些人来说,它可能会添加:
android:windowSoftInputMode="stateHidden|adjustPan"
清单中的活动标记。但这对我没有用。我没有使用AutoCompleteTextView对布局的xml进行其他一些更改。
那么对我有用的是使用setDropdownHeight& AutoCompleteTextview的TextWatcher中的setDropdownVerticalOffset。
我做了以下事情:
helper.spinnerCreator = new SpinnerAdapter(context, R.layout.row_spinner, newusers);
autoCompleteTextView.setAdapter(helper.spinnerCreator);
height = getCorrectOffset(newusers.size());
autoCompleteTextView.setDropDownHeight(height);
autoCompleteTextView.setDropDownVerticalOffset(-(height + offset));
为了获得高度,我做了这样的事情:
private int getCorrectOffset(int items) {
float height = rowHeight * (float) items;
if (items > 2) height = rowHeight * 2.7f;
int s = (int) height;
return s;
}
偏移量是自动完成文本视图的高度。而rowHeight是上下文列表中每行的高度(以像素为单位)。