android 5.0弹出窗口剪辑不起作用

时间:2015-09-20 11:57:45

标签: android android-5.0-lollipop popupwindow

我有一个圆圈的弹出窗口,我希望它部分超出屏幕范围。要调用我使用的窗口:popup.showAsDropDown(imageButton, OFFSET_X, OFFSET_Y);它应该如下所示:

enter image description here

要剪辑我使用的视图:popup.setClippingEnabled(false); 并且它可以工作,它看起来像我期望API级别低于21的设备......

不幸的是,在Android L(棒棒糖)上它看起来像这样:

enter image description here

圆圈被剪裁在顶部,但在右侧它只是到达屏幕的边缘。任何想法如何解决这个问题?

我附上我调用弹出窗口的源代码

private void showPopup(final Activity context, ImageButton imageButton ) {
    // Inflate the popup_layout.xml
    FrameLayout viewGroup = (FrameLayout) context.findViewById(R.id.popup);
    final LayoutInflater layoutInflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View layout = layoutInflater.inflate(R.layout.popup, viewGroup);

    layout.startAnimation(range_animation_start);

    layout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

    int popupHeight = layout.getMeasuredHeight();
    int popupWidth = layout.getMeasuredWidth();
    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(layout);
    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 =getResources().getDimensionPixelOffset(R.dimen.width_offset);
    int OFFSET_Y = getResources().getDimensionPixelOffset(R.dimen.height_offset);

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

    // Displaying the popup at the specified location, + offsets.

    popup.showAsDropDown(imageButton, OFFSET_X, OFFSET_Y);

0 个答案:

没有答案