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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With