我的回收站视图带有单击侦听器。单击查看器时会显示弹出菜单。问题是弹出菜单显示在所单击项目的左上角。是否可以在单击的位置显示弹出菜单?
private fun showPopup(view: View, item: BaseModel) {
val popup = PopupMenu(context!!, view, Gravity.CENTER)
popup.inflate(R.menu.docs_menu)
popup.setOnMenuItemClickListener({ itemMenu: MenuItem ->
when (itemMenu.itemId) {
R.id.del -> {
if (item is AutoRecord){
presenter.onAutoDelete(item)
} else{
presenter.onDriverDelete(item as DriverRecord)
}
}
}
true
})
popup.show()
}
用法:
driverAdapter.onLongItemClick = { item, view ->
showPopup(view, item)
}