Android:以编程方式获取桌面上小部件相对于其他小部件的位置
在 Android 上,用户可以在桌面上放置一个小部件,然后通过长按并在按住时移动手指来移动它。
是否可以以编程方式获取屏幕上通过长触摸移动小部件的位置?
我需要我的桌面小部件知道它是否靠近设备屏幕的边缘。根据它是在桌面顶部还是底部,将选择小部件的不同布局。
我希望这个位置不是以像素为单位给出的,而是以一对从 0 为基础的索引给出的。例如,如果设备可以在桌面上显示 4x7 单元格,则右下角的小部件应该具有坐标 (3, 6)。此外,应该可以以某种方式询问设备屏幕上适合多少个单元格。
或者我误解了什么?
On Android the user can place a widget on the desktop and then to move it by long touch and moving the finger while still holding.
Is it possible to programmatically get the position on the screen where the widget was moved by long touch?
I need my desktop widget to know if it's near the edge of the screen of the device. Depending on whether it's on the top of the desktop or at the bottom different layouts for the widget will be chosen.
I would expect that this position is not given in pixels, but as pair of 0-based indexes. E.g. if the device can display 4x7 cells on the desktop, the widget in the bottom-right corner should have coords (3, 6). Also it should be somehow possible to ask the device how many cells fit into the screen.
Or am I misunderstanding something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Android 2.1 及更高版本上,对于某些选定的主屏幕,您可以通过
getSourceBounds()
单击应用程序小部件时找到它所在的位置 - 该值附加到任何Intent 您通过
setOnClickPendingIntent()
通过PendingIntent
生成。但是:
,因此,我认为你所说的目标(“根据它是在桌面顶部还是在底部,将选择小部件的不同布局”)是不可能的。
On Android 2.1 and later, with some select home screens, you can find out where an app widget resides when it is clicked via
getSourceBounds()
-- this value is attached to anyIntent
you spawn via aPendingIntent
viasetOnClickPendingIntent()
.However:
Hence, I think your stated goal ("Depending on whether it's on the top of the desktop or at the bottom different layouts for the widget will be chosen") is impossible, I think.