Application widget: can you specify the minimum size and default size?

When you create an application widget, you specify the minimum width and height for this widget. When the user places a new widget, the minimum width and height seem to go over to the default size of the widget (in terms of blocks).

In other words, the original widget layout corresponds to the minimum widget size (which they can subsequently change).

Is it possible to indicate that you want the widget to be initially laid out in accordance with the default size, while at the same time setting minimum sizes 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 space. So I want to set the default value in accordance with what, in my opinion, looks better, and the minimum is what really is the lower limit.

+5
source share
1 answer

That's right - in the definition of metadata for the widget provider information for your application, you can use

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

For instance:

<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 and the minimum size is 2 x 1

+14
source

Source: https://habr.com/ru/post/1205691/


All Articles