如图要实现点击+号时,出现popwindow:

222.png
//anchor锚点view
private void showSelectDialog(View anchor) {
View outerView = LayoutInflater.from(this).inflate(R.layout.dialog_chat, null);
//1.这里使用WRAP_CONTENT时可以根据布局大小来灵活掌握
PopupWindow popupWindow = new PopupWindow(outerView,ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.setOnDismissListener(() -> {
Utils.changeWindowAlfa(1f, this);
});
Utils.changeWindowAlfa(0.7f, this);
popupWindow.showAsDropDown(anchor, 0, 0, Gravity.END);
}
//R.layout.dialog_chat
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:layout_marginEnd="@dimen/dp_20"
android:background="@drawable/bg_chat_main"
android:orientation="vertical">
注意代码中1,2,3,4的注释,助你灵活掌握popwindow的大小和间距。