Android view.getLocationOnScreen(位置)返回错误的Y坐标 这会导致另一种观点在第一视角中间的某个地方,而不是它的顶部。
这基本上就是setLocation方法的逻辑:Android view.getLocationOnScreen(位置)返回错误的Y坐标 这会导致另一种观点在第一视角中间的某个地方,而不是它的顶部。,android,Android,这基本上就是setLocation方法的逻辑: int[] locations = new int[2]; view.getLocationOnScreen(locations); int x = locations[0]; int y = locations[1]; otherView.setLocation(x, y); 只是猜测,但我注意到您没有确保默认生成的对话框的边距为零。也许可以试试这个: final Dialog dialog = new Dialog(getActivity()
int[] locations = new int[2];
view.getLocationOnScreen(locations);
int x = locations[0];
int y = locations[1];
otherView.setLocation(x, y);
只是猜测,但我注意到您没有确保默认生成的对话框的边距为零。也许可以试试这个:
final Dialog dialog = new Dialog(getActivity());
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
dialog.setContentView(R.layout.custom_dialog);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(Color.TRANSPARENT));
WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes();
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
layoutParams.x = mX;
layoutParams.y = mY;
dialog.getWindow().setAttributes(layoutParams);
return dialog;
WindowManager.LayoutParams lp...
lp.horizontalMargin = 0;
lp.verticalMargin = 0;