11

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.

drmrbrewer
  • 11,491
  • 21
  • 85
  • 181

1 Answers1

25

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

ra3o.ra3
  • 852
  • 1
  • 8
  • 7
  • 1
    I would add that there's a recommended minimum size depending on the number of cells that you want to use. More info: https://developer.android.com/guide/practices/ui_guidelines/widget_design.html – adalpari Aug 01 '17 at 11:22
  • 2
    Why the non-standard sizes? Docs say the sizes for 4x2/2x1 should be android:minWidth="250dp" android:minHeight="110dp" android:minResizeWidth="110dp" android:minResizeHeight="40dp" – Robin Davies Mar 31 '19 at 08:37