Determine the homescreen's appwidgets space grid size

前端 未结 4 1754
执笔经年
执笔经年 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:08

    I don't know of a way to make a reliable preview, but it might help to use different margins based on orientation. You can use layout-land and layout-port to specify different layouts with different margins.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-06 17:24

    I know it's been awhile, but I was just upvoted on my other answer so I got the chance to glance at this with fresh eyes.

    I think the real answer to the original question might be to set the widget's size yourself, or maybe just the height since that seems to be the problem in the screenshots. In your layout set layout_height="@dimen/my_perfect_height" and the launcher will center it within the cell. If you need a little flexibility, you can use a few different layouts with different metrics and let the user choose between them. And of course, you'll have no problem previewing that height since you're the one setting it.

    0 讨论(0)
  • 2021-01-06 17:29

    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?

    No. Each home screen developer is welcome to do what that developer wishes.

    in this launcher it looks pretty small in landscape mode and very big in portrait mode

    Then come up with a design that accommodates those sizes. For example, you might look to see what other app widgets do when run on that home screen.

    0 讨论(0)
提交回复
热议问题