Android 5.0 popup window cropping not working

I have a popup that represents a circle, and I want it to be partially off-screen. To call the window, I used: popup.showAsDropDown(imageButton, OFFSET_X, OFFSET_Y);And it should look like this:

enter image description here

To copy the view I used: popup.setClippingEnabled(false); And it works, it looks as I expect on devices with an API level below 21 ...

Unfortunately, on android L (candy), it looks like this:

enter image description here

The circle is cropped on top, but on the right side it just fits to the edge of the screen. Any ideas how to solve this problem?

I add the source code in which I call the popup

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 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);
+4
source share

Source: https://habr.com/ru/post/1608206/


All Articles