Add gravity settings to PopupWindow/ListPopupWindow/PopupMenu
Allow calling code to specify left/right/start/end gravity when
showing a popup attached to an anchor. This allows easy alignment of
either the right or left edges of the popup and anchor view.
Bug 10728401
Change-Id: Ie0844a04ea0576fa67b0972f5873aaa4c5b823f6
diff --git a/core/java/com/android/internal/view/menu/MenuPopupHelper.java b/core/java/com/android/internal/view/menu/MenuPopupHelper.java
index dbb78c2..05e9a66 100644
--- a/core/java/com/android/internal/view/menu/MenuPopupHelper.java
+++ b/core/java/com/android/internal/view/menu/MenuPopupHelper.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.content.res.Resources;
import android.os.Parcelable;
+import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
@@ -69,6 +70,8 @@
/** Cached content width from {@link #measureContentWidth}. */
private int mContentWidth;
+ private int mDropDownGravity = Gravity.NO_GRAVITY;
+
public MenuPopupHelper(Context context, MenuBuilder menu) {
this(context, menu, null, false);
}
@@ -102,6 +105,10 @@
mForceShowIcon = forceShow;
}
+ public void setGravity(int gravity) {
+ mDropDownGravity = gravity;
+ }
+
public void show() {
if (!tryShow()) {
throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
@@ -126,6 +133,7 @@
if (addGlobalListener) mTreeObserver.addOnGlobalLayoutListener(this);
anchor.addOnAttachStateChangeListener(this);
mPopup.setAnchorView(anchor);
+ mPopup.setDropDownGravity(mDropDownGravity);
} else {
return false;
}