ShowAtLocation方法用于將View顯示在指定的位置上,具體使用方法如下:
View view = findViewById(R.id.your_view_id);
View parentView = findViewById(R.id.parent_view_id);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
view.setLayoutParams(layoutParams);
int x = 100; // x坐標
int y = 200; // y坐標
popupWindow.showAtLocation(parentView, Gravity.NO_GRAVITY, x, y);
通過以上步驟,就可以將指定的View顯示在指定的位置上。