我创建了一个ListPopupWindow并将其锚定到EditText视图。
private fun openAddressSuggestions() {
val products = arrayOf("address address", "address address", "address address", "address address", "address address", "address address")
val adapter = ArrayAdapter(
context, R.layout.address_suggestion_list_item, products
)
popUpList = androidx.appcompat.widget.ListPopupWindow(requireContext())
popUpList?.setAdapter(adapter)
popUpList?.anchorView = startView
popUpList?.width = startView.width
popUpList?.height = measureContentWidth(adapter)
popUpList?.isModal = false
popUpList?.setOnItemClickListener(this)
popUpList?.show()
}
}
因此,当平板电脑处于纵向模式时,它看起来不错。但是在横向模式下,列表会向上移动,因此键盘不会覆盖它。但随后它涵盖了Anchor视图。
如果我删除行popUpList?.height = measureContentWidth(adapter)
,则它会正确显示在锚定视图中,但是如果我只在视图中放置两个项目,它的底部将有一堆空白。我需要弹出窗口足够高以仅显示添加的视图。
如何使ListPopUpWindow保持锚定,即使这意味着它的一部分不在屏幕上?