I just want to know how big my current widget is. I found tons of questions to set the minimum size, but I don\'t want to set it. Instead I want to show that informations which
You can add an method to your widget provider and get your widget sizes when you resize it for all versions of Android started from API 16:
@Override
public void onAppWidgetOptionsChanged (Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle widgetInfo) {
int width = widgetInfo.getInt (AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH);
int height = widgetInfo.getInt (AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT);
}
And as for new added widget you can get its wizes by getting its sizes from its layout and multiply it to its cols num:
AppWidgetProviderInfo widgetInfo = AppWidgetManager.getInstance (context).getAppWidgetInfo (widgetId);
private int getColsNum (int size) {
return (int) Math.floor ((size - 30) / 70);
}
public int getWidthColsNum () {
return getColsNum (widgetInfo.minWidth);
}
public int getHeightColsNum () {
return getColsNum (widgetInfo.minHeight);
}
int width = widgetInfo.minWidth * getWidthColsNum ();
int height = widgetInfo.minHeight * getHeightColsNum ();
Getting widget cols num was taken from official Android guidelines.