2015-10-20 33 views

回答

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); 

希望它會幫助你。 乾杯!