安卓:编程获得相对于其他部件的桌面小部件的位置 [英] Android: programmatically get position of the widget on desktop relative to other widgets

查看:116
本文介绍了安卓:编程获得相对于其他部件的桌面小部件的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android的用户可以将一个插件的桌面上,然后通过长按移动,并移动手指,同时仍持有。

是否有可能以编程方式获得,其中小部件被移到由长触摸屏幕上的位置?

我需要我的桌面widget知道,如果它的设备的屏幕边缘附近。取决于它是否是在桌面上的顶部或在该部件将被选择底部的不同布局。

我希望,这一立场没有以像素为单位给出,而是作为对从零开始的索引。例如。如果该设备可以在桌面上显示4X7细胞,在右下角的插件应具有的coords(3,6)。此外,它应该以某种方式可能要求设备有多少细胞适应屏幕。

还是我误解的东西?

解决方案

在Android 2.1及更高版本,有一些选择主屏幕,就可以找出一个应用程序窗口小部件位于它是通过 getSourceBounds点击时() - 这个值被附加到任何意图您是通过生成一个 PendingIntent 通过 setOnClickPendingIntent()

不过:<​​/ P>

  • 在此只能在Android 2.1及更高版本
  • 不是所有的家庭屏幕可能做到这一点,因为这是启动code IIRC的一部分
  • 坐标是在像素IIRC
  • 有没有办法来询问主屏幕,找出该信息的任何其他的方式,因为没有API与主屏幕互动

因此​​,我认为你的既定目标(视无论是在桌面的顶部或底部的不同布局的部件将被选择)是不可能的,我想。

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?

解决方案

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 any Intent you spawn via a PendingIntent via setOnClickPendingIntent().

However:

  • this only works on Android 2.1 and newer
  • not all home screens might do this, as this is part of the Launcher code IIRC
  • the coordinates are in pixels IIRC
  • there is no way to interrogate the home screen to find out this information any other way, since there is no API to interact with the home screen

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.

这篇关于安卓:编程获得相对于其他部件的桌面小部件的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆