質問編集履歴
1
コードの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,6 +22,40 @@
|
|
22
22
|
|
23
23
|
mPopupWindow = new PopupWindow(MainActivity.this);
|
24
24
|
|
25
|
+
// レイアウト設定
|
26
|
+
View popupView = getLayoutInflater().inflate(R.layout.popup_layout, null);
|
27
|
+
|
28
|
+
|
29
|
+
popupView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
|
30
|
+
@Override
|
31
|
+
public void onClick(View v) {
|
32
|
+
if (mPopupWindow.isShowing()) {
|
33
|
+
mPopupWindow.dismiss();
|
34
|
+
|
35
|
+
}
|
36
|
+
}
|
37
|
+
});
|
38
|
+
|
39
|
+
mPopupWindow.setContentView(popupView);
|
40
|
+
// 背景設定
|
41
|
+
mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.popup_background));
|
42
|
+
|
43
|
+
// タップ時に他のViewでキャッチされないための設定
|
44
|
+
mPopupWindow.setOutsideTouchable(true);
|
45
|
+
mPopupWindow.setFocusable(true);
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
// 表示サイズの設定 今回は幅300dp
|
51
|
+
float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 300, getResources().getDisplayMetrics());
|
52
|
+
mPopupWindow.setWindowLayoutMode((int) width, WindowManager.LayoutParams.WRAP_CONTENT);
|
53
|
+
mPopupWindow.setWidth((int) width);
|
54
|
+
mPopupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
|
55
|
+
|
56
|
+
// 画面中央に表示
|
57
|
+
mPopupWindow.showAtLocation(findViewById(R.id.show_button), Gravity.CENTER, 0, 0);
|
58
|
+
|
25
59
|
```
|
26
60
|
こような形で,インスタンスを生成しているのですが,これだと1個しか生成できないです.
|
27
61
|
|