Calculate height of appwidget

后端 未结 1 561
我寻月下人不归
我寻月下人不归 2021-02-06 10:32

I cannot figure out or find a solution by googling for this problem. I have an android app with an appwidget, looks like http://www.livescorewidget.eu/img/screendumps/widget.png

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-06 11:01

    From Jelly Bean onwards you can get a Bundle object containing widget dimensions using the getAppWidgetOptions() method in AppWidgetManager:

    Bundle options = appWidgetManager.getAppWidgetOptions(widgetId);
    
    int minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
    int maxWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH);
    
    int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
    int maxHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT);
    

    minWidth and maxHeight are the dimensions of your widget when the device is in portrait orientation, maxWidth and minHeight are the dimensions when the device is in landscape orientation. All in dp.

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