android - 有没有办法强制 AutoCompleteTextView 的上下文列表显示在 View 上方?

标签 android

我有一个自定义的 AutoCompleteTextView。当我在列表中有多个结果时,上下文列表显示在 AutoCompleteTextView 上方,但是当它将答案缩小到 1 时,上下文列表被移动,因此它在 AutoCompleteTextView 下方,我的情况是将它放在软键盘下方,以便您可以看到它的结果。

这是一个列表中包含 2 个项目的示例。 an example with 2 items in the list

结果移到了下面: and here the result has moved below

我知道列表在那里,所以它不是因为没有结果。 那么有没有办法强制列表显示在 AutoCompleteTextView 上方?

最佳答案

我想出了一个办法。

对于某些人来说,它可能适用于添加:

android:windowSoftInputMode="stateHidden|adjustPan"

list 中的 Activity 标签。但这对我不起作用。也没有对我拥有 AutoCompleteTextView 的布局的 xml 进行一些其他更改。

所以对我有用的是在 AutoCompleteTextview 的 TextWatcher 中使用 setDropdownHeight 和 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;
}

偏移量是自动完成 TextView 的高度。 rowHeight 是上下文列表中每行的高度(以像素为单位)。

关于android - 有没有办法强制 AutoCompleteTextView 的上下文列表显示在 View 上方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27292474/

相关文章:

android - NotificationManager.cancel() 不起作用 : Notification isn't removed

android - 由于 multidex/android 错误,在 Travis 中构建失败?

java - 如何访问 getFilesDir() 作为环境变量?

android - 未签名的应用程序在已签名的情况下有效?

android - 离线时在 webview 中加载 pdf

c# - 在 Unity3D 中创建 Android XMPP 聊天客户端的最佳方式

java - 应用程序已停止 android 模拟器 genymotion

Android 应用在发布到 Play 商店后无法运行

java - 当应用程序来自后台时更改菜单图标(在 onResume() 方法中)

javascript - 如何获取 Android WebView 中从顶部到 div block 的像素数量?