1
我有一個按鈕,其單擊彈出一個對話框。對話框正在顯示在中心。但我想顯示它只是按鈕下方。如何做到這一點?如何在特定位置顯示自定義對話框?
我嘗試使用彈出窗口also.Here是代碼
private void showPopup(final Activity context, Point p)
{
Display display = getWindowManager().getDefaultDisplay();
width = display.getWidth(); // deprecated
height = display.getHeight(); // deprecated
int popupWidth =width;
int popupHeight =height;
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.datepicker_popup, viewGroup);
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth+p.x);
popup.setHeight(popupHeight+p.y);
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 = 7;
int OFFSET_Y = 65;
// 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);
// Getting a reference to Close button, and close the popup when clicked.
Button close = (Button) layout.findViewById(R.id.close);
close.setOnClickListener(new OnClickListener()
{
/* disable(content_view);*/
@Override
public void onClick(View v)
{
popup.dismiss();
}
});
}
第二個代碼正在爲我工作,但我需要的是顯示對話框下方的按鈕,其單擊彈出對話框。如何做到這一點? – Nevaeh
我也試過。請參閱更新後的問題。如何改變窗口的位置? – Nevaeh
檢查此http://rajeshandroiddeveloper.blogspot.in/2013/07/android-popupwindow-example-in-listview.html –