弹出菜单不扩展(弹出高度始终相同)

时间:2014-12-08 15:13:51

标签: android android-menu android-popupwindow

MainActivity extends android.support.v7.app.ActionBarActivity

来自MainActivity.java的代码

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here.
    int id = item.getItemId();
    switch (id) {
    case R.id.action_sort:
        showSortPopup(item.getActionView());
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

public void showSortPopup(View view) {
    PopupMenu popup = new PopupMenu(MainActivity.this, view);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.sort_menu, popup.getMenu());
    popup.show();
}

sort_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:id="@+id/action_ascending"
              android:title="Ascending" />
        <item android:id="@+id/action_descending"
              android:title="Descending" />
</menu>

这是选择 R.id.action_sort 操作栏菜单时显示的弹出菜单:

Popup bug preview

它有效,我的意思是我可以滚动它来查看其他菜单项,但为什么它没有扩展?

0 个答案:

没有答案