问题
How to force PopupMenu to overlap anchor? I would like to recreate something similar to this:

回答1:
Setting overlapAnchor allowed me to overlap anchor view without setting offset:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="popupMenuStyle">@style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="@style/Widget.AppCompat.Light.PopupMenu">
<item name="overlapAnchor">true</item>
</style>
The PopupMenu wraps a ListPopupWindow inside it. This ListPopupWindow wraps AppCompatPopupWindow using this overlapAnchor attribute. All this in the support library.
回答2:
Alternative to Paritosh Tonk's answer:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="popupMenuStyle">@style/Widget.AppCompat.Light.PopupMenu.Overflow</item>
</style>
or for dark theme:
<style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
<item name="popupMenuStyle">@style/Widget.AppCompat.PopupMenu.Overflow</item>
</style>
回答3:
Setting android:dropDownVerticalOffset
allowed me to overlap anchor view:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="popupMenuStyle">@style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="@style/Widget.AppCompat.Light.PopupMenu">
<item name="android:dropDownVerticalOffset">-36dip</item>
</style>
回答4:
Have you looked at using PopupWindow instead? Those offer a bit more flexibility in their placement. You can specify the anchor view and an x and y offset which would let you define the overlap.
回答5:
I came here when trying to figure out how to create a popup menu that overlaps its anchor when the anchor is in the actionBar. Since this is a prominent search result for that problem, I want to leave the answer here even though I'm not sure whether the solution would work for OP.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<!-- This item will expand into a submenu -->
<item
android:id="@+id/anchor"
android:icon="@drawable/ic_anchor"
android:title="@string/anchor"
app:showAsAction="always">
<menu>
<item
android:id="@+id/subMenuItemOne"
android:showAsAction="never"
android:title="SubMenuItemOne"/>
<item
android:id="@+id/subMenuItemTwo"
android:showAsAction="never"
android:title="SubMenuItemTwo"/>
</menu>
</item>
</menu>
来源:https://stackoverflow.com/questions/28202380/how-to-force-popupmenu-to-overlap-anchor