Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android widget max allowed size

We can set the MINIMUM size of a widget using e.g.

android:minHeight="40dp"
android:minResizeHeight="40dp"
android:minResizeWidth="40dp"
android:minWidth="40dp"

There are no android:max___ properties.

Is there a way to limit the MAXIMUM size of a resizeable widget?

(perhaps a resize callback I'm not seeing or something like that?)


Noting that the docs say a common use case for resizing is lists or grids. Which require no setting of a max size.

My use case is simply "client asked for a single widget that is either 1x1 or 2x2". Will he get what he wants, or will I have to change his mind for him?

like image 882
Richard Le Mesurier Avatar asked Dec 20 '22 18:12

Richard Le Mesurier


1 Answers

Is there a way to limit the MAXIMUM size of a resizeable widget?

NO, but you can limit the user by disable the horizontal or vertical re-sizing in the XML file of your widget.

Example: for only Horizontal

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/widget_layout"
android:minHeight="220dp"
android:minWidth="180dp"
android:resizeMode="horizontal"
android:updatePeriodMillis="0" 
android:previewImage="@drawable/widget_all_in_one_preview"/>

Example: for only Vertical

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/widget_layout"
android:minHeight="220dp"
android:minWidth="180dp"
android:resizeMode="vertical"
android:updatePeriodMillis="0" 
android:previewImage="@drawable/widget_all_in_one_preview"/>

You can also do both by:

android:resizeMode="horizontal|vertical"

Make sure you are using NinePatch images or setting the Background color programatically.

OR provide a fixed size Widget to be in the safe side :)

I hope it helps

like image 187
Sami Eltamawy Avatar answered Jan 04 '23 13:01

Sami Eltamawy