确定主屏幕的appwidgets空间网格大小

问题描述:

我已经开发出一种重相当大的应用程序,小部件的平板电脑。该应用程序小部件的工作原理很好的大多数设备与广大发射的,但也有一些问题,在纵向模式下的方位尤其是对GO-HD启动。该应用程序小部件的高度过大,并不好看。

I have developed a re-sizable app-widget for tablets. The app-widget works nice on most devices with the majority of launchers, however there are some problems with the orientation especially on the GO-HD Launcher in portrait mode. The height of the app-widget is too big and doesn't look nice.

为了处理这个我创建了一个方法,以允许用户设置任何多余的空间,在应用程序,小部件的空间,他想使它看起来不错。例如,他可以将额外的20像素的上边距当设备处于纵向模式,只有5个像素时,以横向等。

In order to deal with this I have created a method to allow the user to set any extra margins, in the app-widget space, he wants to make it look nice. For example he can set extra 20 pixels top margin when the device is in portrait mode and only 5 pixels when in landscape etc.

现在,我创建活动,允许用户设置页边距。我想打一个小preVIEW区(它会使用相同的背景绘制的应用程序,小部件的线性布局有),以便用户获得的应用程序,小工具将如何看起来像在主屏幕上的想法这些利润。其实我已经做到了,但结果是远离现实。

Now I am creating an activity to allow users to set the margins. I want to make a small preview area (it will be a linear layout with the same background drawable app-widget has) in order for the user to get an idea of how the app-widget will look like on the home screen with these margins. Actually I have done that but the result is far away from the reality.

所以我的问题是:

有没有什么办法让大小(或接近),其发射使用的应用程序放置在主屏幕上的应用程序,小部件的网格单元?请注意,我知道一个事实,即并非所有发射继Android的公式,这一点,但我要的是得到一个方法来计算它的近似值。

Is there any way to get the size (or close to it) of the grid cell that launcher application using to place the app-widgets on the home screen? Please note that I am aware of the fact that not all launchers following the Android formulas for this but what I want is to get a way to calculate an approximation of it.

----编辑----

为了更好地理解我的问题,我创建了一个屏幕截图:

In order to better understand my problem I have created a screenshot:

首先,所有的应用程序,小部件的背景是一个没有图形或尺寸在所有的形状xml文件。它是由机器人绘制它的可用空间。在我看来这是最好的GUI设计(至少与背景)。现在,在屏幕1中可以看到小部件在纵向模式中的默认的Andr​​oid发射器,它看起来非常漂亮,它是调整大小确定。在屏幕2和3,你可以看到它在GO-HD发射器(横向和纵向模式),在这个发射器,它看起来pretty的小风景模式和非常大的纵向模式。我可以让用户调整页边距,你可以在屏幕上看到4解决这个问题。

First of all the app-widget's background is a shape xml file with no graphics or dimensions at all. It's up to Android to draw it in the available space. In my opinion this is the best GUI design (at least with the background). Now in the screen 1 you can see the widget in portrait mode in the default Android launcher, it looks very nice and it is re-sizing OK. In screen 2 and 3 you can see it in GO-HD launcher (landscape and portrait mode), in this launcher it looks pretty small in landscape mode and very big in portrait mode. I can fix this problem by letting the user adjust the margins as you can see in screen 4.

如果你比较preVIEW(暗区在屏幕4的中心)与原来的应用程序,小部件Android的默认启动,你可以看到,有没有一个很好的匹配。我所问的是我怎么能present给用户带来更好的preVIEW(最接近实际应用,小部件)。

If you compare the preview (the dark area in the center of screen 4) with the original app-widget in android's default launcher you can see that there is no a good match. What I am asking is how can I present to the user a better preview (closest to the actual app-widget).

感谢你,请原谅我的英语水平

Thank you and please forgive my English

您是否落实 AppWidgetProvider.onAppWidgetOptionsChanged(背景下,AppWidgetManager,INT,捆绑)?所有乖巧发射应报告有关您放置小部件,它可以从包中检索某些指标,用code这样的:

Have you implemented AppWidgetProvider.onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle)? All well-behaved launchers should report some metrics about your placed widget, which you can retrieve from the bundle, using code like:

int minwidth_dp = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
int maxwidth_dp = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH);
int minheight_dp = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
int maxheight_dp = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT);

请注意,有小区的概念在这里 - 。这些指标符合您的小部件的实际大小,但许多细胞它占用

Note that there is no concept of cell here - these metrics correspond to the actual size of your widget, however many cells it takes up.

该股启动这些映射到不同的方向,像这样:

The stock launcher maps these to different orientations like so:

了minWidth - >纵向宽度
  了minHeight - >景观高度
  了maxWidth - >横向宽度
  了maxHeight - >纵向高度

minwidth -> portrait width
minheight -> landscape height
maxwidth -> landscape width
maxheight -> portrait height

这保持在两个方向行数和列数相同,并且调整大小的细胞以适应屏幕,应当映射这些相同的方式不限发射器。请注意,假设这些关系一直持有,如果你是嵌入在发射器,做一些不寻常的,其部件可能会产生意外的结果 - 将它们放置在屏幕的一部分,或者使用不同数量的不同方向的行或列。

Any launcher that keeps the same number of rows and columns in both orientations, and that resizes the cells to fit the screen, ought to map these the same way. Be aware, assuming these relationships always hold may produce undesired results if you're embedded in a launcher that does something unusual with its widgets - placing them in only part of the screen, or using a different number of rows or columns in different orientations.

另外,一些发射器可能会报告在这两个MIN-和最大值值电流方向的指标,并只需再次打电话给你时,新指标的方向变化。但是,如果你只关心当前的方向,这些发射器的行为与该股票发射器兼容。

Alternately, some launchers may report the metrics of the current orientation in both min- and max- values, and simply call you again with new metrics when the orientation changes. However, if you are only interested in the current orientation, the behavior of these launchers is compatible with that of the stock launcher.