Poupwindow
PopupWindow相对于兄弟控件的弹框

rivate void getPopupWindow() {
PopupWindow popupWindow = new PopupWindow(this);
View view = View.inflate(this, R.layout.sim, null);
button = view.findViewById(R.id.button1);
popupWindow.setHeight(200);
popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setContentView(view);
popupWindow.setOutsideTouchable(true);
popupWindow.showAsDropDown(tv,0,200);
}
PopupWindow相对于父类控件的弹框

private void getPopupWindow1() {
final PopupWindow popupWindow = new PopupWindow(this);
View view = View.inflate(this, R.layout.sim, null);
button = view.findViewById(R.id.button1);
popupWindow.setHeight(200);
popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "你点了我", Toast.LENGTH_SHORT).show();
}
});
popupWindow.setContentView(view);
popupWindow.setOutsideTouchable(true);
View view1 = View.inflate(this, R.layout.activity_main, null);
WindowManager.LayoutParams attributes = getWindow().getAttributes();
attributes.alpha = 0.5f;
getWindow().setAttributes(attributes);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
WindowManager.LayoutParams attributes = getWindow().getAttributes();
attributes.alpha = 1.0f;
getWindow().setAttributes(attributes);
}
});
popupWindow.showAtLocation(view1, Gravity.BOTTOM, 0, 0);
}