Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android view.getLocationOnScreen(位置)返回错误的Y坐标 这会导致另一种观点在第一视角中间的某个地方,而不是它的顶部。_Android - Fatal编程技术网

Android view.getLocationOnScreen(位置)返回错误的Y坐标 这会导致另一种观点在第一视角中间的某个地方,而不是它的顶部。

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()

这基本上就是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());
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;