Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android.R.id.content 为null #11

Closed
HH-Ding opened this issue Mar 27, 2019 · 15 comments
Closed

android.R.id.content 为null #11

HH-Ding opened this issue Mar 27, 2019 · 15 comments

Comments

@HH-Ding
Copy link

HH-Ding commented Mar 27, 2019

view.getRootView().findViewById(android.R.id.content) 到这步,获取为null,百度,google没找到,请问这个是什么原因?

@xujiaji
Copy link
Owner

xujiaji commented Mar 27, 2019

你试试直接用view.getRootView()试试呢

@HH-Ding
Copy link
Author

HH-Ding commented Mar 27, 2019

试过了,view.getRootView() 跟注释掉这段一样的效果

@xujiaji
Copy link
Owner

xujiaji commented Mar 27, 2019

尝试过安装一下demo看会报错吗?

@HH-Ding
Copy link
Author

HH-Ding commented Mar 28, 2019

没有报错,所以感觉传进去的自定义view有关系,我的是悬浮窗的自定义 view

@xujiaji
Copy link
Owner

xujiaji commented Mar 28, 2019

那你把这几句都注释了试试!

 int[] contentLocation = new int[2];
        view.getRootView().findViewById(android.R.id.content).getLocationOnScreen(contentLocation);
        clickedViewLocation[0] -= contentLocation[0];
        clickedViewLocation[1] -= contentLocation[1];

@HH-Ding
Copy link
Author

HH-Ding commented Apr 1, 2019

注释掉可以,就是显示位置有点偏移

@xujiaji
Copy link
Owner

xujiaji commented Apr 1, 2019

因该是向下偏移了个状态栏的高度吧?

@HH-Ding
Copy link
Author

HH-Ding commented Apr 1, 2019

跟上一个问题的显示问题差不多

@xujiaji
Copy link
Owner

xujiaji commented Apr 1, 2019

在这里你计算一下状态栏高度,然后减去这个高度因该就可以了

@xujiaji
Copy link
Owner

xujiaji commented Apr 1, 2019

clickedViewLocation[1] -= 状态栏高度

@HH-Ding
Copy link
Author

HH-Ding commented Apr 1, 2019

好,我搞搞

@xujiaji
Copy link
Owner

xujiaji commented Apr 1, 2019

恩,或则通过setOffsetX setOffsetY设置当前位置的偏移也许能达到更符合你的效果

@HH-Ding
Copy link
Author

HH-Ding commented Apr 1, 2019

现在就是通过setOffsetX 和setOffsetY设置,来达到效果的

@xujiaji
Copy link
Owner

xujiaji commented Apr 1, 2019

恩,这里看来也得判断一下,没有考虑到悬浮窗的问题。这里的代码就是为了解决上一个问题

xujiaji added a commit that referenced this issue Apr 1, 2019
xujiaji added a commit that referenced this issue Apr 7, 2019
@xujiaji
Copy link
Owner

xujiaji commented Apr 7, 2019

已更新,v1.1.7已修复

@xujiaji xujiaji closed this as completed Apr 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants