Calculate height of appwidget

﹥>﹥吖頭↗ 提交于 2020-01-29 08:02:43

问题


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, and I am adding the data rows on the fly. Due to different devices the height of the widget is different and therefore a different amount of space is available for my rows. I want to know how many dips or pixels my widget uses so I can calculate how many rows there is room for. Is it possible?

Even better could be if you could calculate how much height available in the layout for the rows.

Thanks


回答1:


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.



来源:https://stackoverflow.com/questions/16801721/calculate-height-of-appwidget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!