以下は、仕様に従って完璧に動作するはずです。ビューに割り当てられたOnClickListener
のonClick(View v)
内からこのメソッドを呼び出します。
public void showPopup(View anchorView) {
View popupView = getLayoutInflater().inflate(R.layout.popup_layout, null);
PopupWindow popupWindow = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// Example: If you have a TextView inside `popup_layout.xml`
TextView tv = (TextView) popupView.findViewById(R.id.tv);
tv.setText(....);
// Initialize more widgets from `popup_layout.xml`
....
....
// If the PopupWindow should be focusable
popupWindow.setFocusable(true);
// If you need the PopupWindow to dismiss when when touched outside
popupWindow.setBackgroundDrawable(new ColorDrawable());
int location[] = new int[2];
// Get the View's(the one that was clicked in the Fragment) location
anchorView.getLocationOnScreen(location);
// Using location, the PopupWindow will be displayed right under anchorView
popupWindow.showAtLocation(anchorView, Gravity.NO_GRAVITY,
location[0], location[1] + anchorView.getHeight());
}
コメントは十分にこれを説明しなければなりません。 anchorView
は、v
であり、onClick(View v)
である。
これまでのところ素晴らしいですが、どのように境界線などを作っていますか? –
@ popup'レイアウト全体を黒い背景の 'FrameLayout'の内側に配置してください。 'popup'レイアウトの背景を白に設定し、' 2dp'の余白を与えます。 – Vikram
あまりにも複雑です:Dフレームのある背景の画像で行い、内側の色は70%のように透明にしました。とにかく、上記の答えは、私があなたに感謝したものでした –