android.R.id.content 为null
HH-Ding opened this issue · 15 comments
HH-Ding commented
view.getRootView().findViewById(android.R.id.content) 到这步,获取为null,百度,google没找到,请问这个是什么原因?
xujiaji commented
你试试直接用view.getRootView()
试试呢
HH-Ding commented
试过了,view.getRootView() 跟注释掉这段一样的效果
xujiaji commented
尝试过安装一下demo看会报错吗?
HH-Ding commented
没有报错,所以感觉传进去的自定义view有关系,我的是悬浮窗的自定义 view
xujiaji commented
那你把这几句都注释了试试!
int[] contentLocation = new int[2];
view.getRootView().findViewById(android.R.id.content).getLocationOnScreen(contentLocation);
clickedViewLocation[0] -= contentLocation[0];
clickedViewLocation[1] -= contentLocation[1];
HH-Ding commented
注释掉可以,就是显示位置有点偏移
xujiaji commented
因该是向下偏移了个状态栏的高度吧?
HH-Ding commented
跟上一个问题的显示问题差不多
xujiaji commented
在这里你计算一下状态栏高度,然后减去这个高度因该就可以了
xujiaji commented
clickedViewLocation[1] -= 状态栏高度
HH-Ding commented
好,我搞搞
xujiaji commented
恩,或则通过setOffsetX
和setOffsetY
设置当前位置的偏移也许能达到更符合你的效果
HH-Ding commented
现在就是通过setOffsetX 和setOffsetY设置,来达到效果的
xujiaji commented
恩,这里看来也得判断一下,没有考虑到悬浮窗的问题。这里的代码就是为了解决上一个问题
xujiaji commented
已更新,v1.1.7已修复