Determine the homescreen's appwidgets space grid size

前端 未结 4 1779
执笔经年
执笔经年 2021-01-06 16:43

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 orie

4条回答
  •  温柔的废话
    2021-01-06 17:16

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

提交回复
热议问题