Android – App Widget: can you specify a minimum AND a default size

androidandroid-appwidgetwidget

When you design an app widget, you specify a minimum width and height for that widget. When the user places a new widget, the minimum width and height appear to translate across to a default widget size (in terms of blocks).

In other words, the initial widget layout appears to correspond to the minimum widget size specified (which they can subsequently resize).

Is it possible to specify that you want the widget initially to be laid out according a default size, whilst also setting the minimum dimensions below which the user cannot resize the widget later?

In my case, there is a size at which I think the widget looks best, but it still looks OK below that size if the user really wants to save on space. So I want to set the default at what I think looks best, and the minimum at what truly is the lower limit.

Best Answer

That is correct - in the metadata definition of for your app widget provider info you can use

minWidth and minHeight to define your desired / default / best widget size and minResizeWidth and minResizeHeight to define the smallest allowed widget size

For example:

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
  android:minWidth="286.0dp"
  android:minHeight="146.0dp"
  android:resizeMode="vertical|horizontal"
  android:minResizeWidth="146.0dp"
  android:minResizeHeight="72.0dp"
/>

In this case the default size is 4 x 2 cells, and the minimum size is 2 x 1

Related Topic