android – 根据Material design spec创建“Simple Menu”

根据这个
http://www.google.com/design/spec/components/menus.html#menus-simple-menus,第一个菜单项与原始行的垂直中心对齐,如下所示:

《android – 根据Material design spec创建“Simple Menu”》

我正在尝试为ListView项创建此菜单,如下所示:

@Override
public void onListItemClick(ListView l, View v, final int position, long id) {
    PopupMenu popup = new PopupMenu(getContext(), v, Gravity.CENTER_HORIZONTAL);
    popup.getMenuInflater().inflate(R.menu.bus_line_popup, popup.getMenu());
    popup.setOnMenuItemClickListener(...);
    popup.show();
}

然而,菜单然后没有正确显示并根据规范:
《android – 根据Material design spec创建“Simple Menu”》

如何使菜单完全按照要求显示?

最佳答案 我做了一点搜索,参见:
http://developer.android.com/reference/android/widget/PopupMenu.html

A PopupMenu displays a Menu in a modal popup window anchored to a
View
. The popup will appear below the anchor view if there is room, or
above it if there is not
. If the IME is visible the popup will not
overlap it until it is touched. Touching outside of the popup will
dismiss it.

正如doc所说,当有空间时它似乎是正常的,它将显示在视图下方(就像你的情况一样),如果没有roow,它将显示在视图上方.

点赞