确定主屏幕的小工具的空间网格大小 [英] Determine the homescreen's appwidgets space grid size

查看:101
本文介绍了确定主屏幕的小工具的空间网格大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为平板电脑开发了一个可调整大小的应用程序小部件.该应用程序小工具在大多数带有大多数启动器的设备上都可以很好地工作,但是定向方面存在一些问题,尤其是在纵向模式下的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.

现在,我正在创建一个活动,以允许用户设置边距.我想做一个小的预览区域(它将是具有相同背景可绘制应用程序小部件的线性布局),以便用户了解在这些边距下应用程序小部件在主屏幕上的外观.其实我已经做到了,但结果与现实相去甚远.

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:

首先,该应用程序小部件的背景是一个完全没有图形或尺寸的shape xml文件.Android将其绘制在可用空间中.我认为这是最好的GUI设计(至少在背景下).现在,在屏幕1中,您可以在默认的Android启动器中以纵向模式看到小部件,它看起来非常漂亮,并且正在调整大小.在屏幕2和3中,您可以在GO-HD启动器(横向和纵向模式)中看到它,在此启动器中,横向模式下看起来很小,而纵向模式下看起来很大.我可以通过让用户调整屏幕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.

如果将预览(屏幕4中央的深色区域)与android默认启动器中的原始应用程序小部件进行比较,您会发现没有很好的匹配项.我要问的是如何向用户提供更好的预览(最接近实际的应用程序小部件).

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).

谢谢,请原谅我的英语

推荐答案

您是否实现了 AppWidgetProvider.onAppWidgetOptionsChanged(Context,AppWidgetManager,int,Bundle)?所有行为良好的启动器都应报告有关您放置的小部件的一些指标,您可以使用以下代码从捆绑包中检索这些指标:

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.

或者,某些启动器可能会以最小值和最大值报告当前方向的指标,并在方向更改时简单地用新指标再次致电给您.但是,如果您仅对当前方向感兴趣,则这些发射器的行为与库存发射器的行为兼容.

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.

这篇关于确定主屏幕的小工具的空间网格大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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