diff options
| author | Adam Powell <adamp@google.com> | 2013-09-26 15:36:34 -0700 |
|---|---|---|
| committer | Adam Powell <adamp@google.com> | 2013-09-26 15:49:27 -0700 |
| commit | 54c94dea8a26e66fa59a31fd9170ca221052d3aa (patch) | |
| tree | 76575b5ed456ff88aff056c19a43f24d0b36f251 /core/java/android/widget/PopupMenu.java | |
| parent | bde988ade5f75c3d241422dce2ee4124871fab53 (diff) | |
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
Diffstat (limited to 'core/java/android/widget/PopupMenu.java')
| -rw-r--r-- | core/java/android/widget/PopupMenu.java | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/core/java/android/widget/PopupMenu.java b/core/java/android/widget/PopupMenu.java index 9ac6a5969dea..111dadc5f868 100644 --- a/core/java/android/widget/PopupMenu.java +++ b/core/java/android/widget/PopupMenu.java @@ -22,6 +22,7 @@ import com.android.internal.view.menu.MenuPresenter; import com.android.internal.view.menu.SubMenuBuilder; import android.content.Context; +import android.view.Gravity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -64,12 +65,25 @@ public class PopupMenu implements MenuBuilder.Callback, MenuPresenter.Callback { * is room, or above it if there is not. */ public PopupMenu(Context context, View anchor) { + this(context, anchor, Gravity.NO_GRAVITY); + } + + /** + * Construct a new PopupMenu. + * + * @param context Context for the PopupMenu. + * @param anchor Anchor view for this popup. The popup will appear below the anchor if there + * is room, or above it if there is not. + * @param gravity The {@link Gravity} value for aligning the popup with its anchor + */ + public PopupMenu(Context context, View anchor, int gravity) { // TODO Theme? mContext = context; mMenu = new MenuBuilder(context); mMenu.setCallback(this); mAnchor = anchor; mPopup = new MenuPopupHelper(context, mMenu, anchor); + mPopup.setGravity(gravity); mPopup.setCallback(this); } |
