弹出菜单从右边占用一些空间

时间:2015-10-20 06:13:50

标签: android android-layout

我弹出菜单项,从右侧占用一些空间。如何从右侧移除此空间。

enter image description here

请按照屏幕截图进行操作。

1 个答案:

答案 0 :(得分:0)

您可以设置弹出式显示位置以及高度和宽度。

通过以下代码:

   int popupWidth = 200;
   int popupHeight = 150;


final PopupWindow popup = new PopupWindow(context);
   popup.setContentView(layout);
   popup.setWidth(popupWidth);
   popup.setHeight(popupHeight);
   popup.setFocusable(true);

   // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
   int OFFSET_X = 30;
   int OFFSET_Y = 30;

   // Clear the default translucent background
   popup.setBackgroundDrawable(new BitmapDrawable());

   // Displaying the popup at the specified location, + offsets.
   popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);