I'm working on an Android Screen-Widget. The default size (if I drag the Widget from the Widget-List and drop it on my Homescreen) is set to 3x3, but I didn't get where I can change it. Can anyone explain me how to set the default value on another value?
3 Answers
You declare the default size (and other properties) of your Widget in the appwidget-provider xml:
https://developer.android.com/guide/topics/appwidgets/index.html
Specifically the minWidth
and minHeight
properties:
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="40dp"
android:minHeight="40dp"
android:updatePeriodMillis="86400000"
android:previewImage="@drawable/preview"
android:initialLayout="@layout/example_appwidget"
android:configure="com.example.android.ExampleAppWidgetConfigure"
android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen">
</appwidget-provider>
The values for the
minWidth
andminHeight
attributes specify the minimum amount of space the App Widget consumes by default. The default Home screen positions App Widgets in its window based on a grid of cells that have a defined height and width. If the values for an App Widget's minimum width or height don't match the dimensions of the cells, then the App Widget dimensions round up to the nearest cell size.

- 23,133
- 6
- 63
- 84
-
Thanks, thats exactly what i need. Is there any way to set the default size to the whole page? – J. Doe Sep 15 '16 at 12:11
-
I believe it only takes dp values so there's no automatic way to do it as far as I'm aware. – Ken Wolf Sep 15 '16 at 12:45
-
@KenWolf Is there any way we can restrict the max size of widget as well? – Love Garg Sep 15 '16 at 14:01
-
You can setting code below:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="146dp"
android:updatePeriodMillis="0"
android:minHeight="146dp"
android:initialLayout="@layout/activity_main">
</appwidget-provider>
If you want to know about details. please visit https://www.tutorialspoint.com/android/android_widgets.htm
It's easy, just go to res > XML > new_app_widget_info.xml , open it then you can find
android:minWidth="320dp"
android:minHeight="72dp"
android:previewImage="@drawable/example_appwidget_preview"
Where two lines about Widget Size and the last one about the image which will show in App Widgets.

- 2,653
- 18
- 24
-
Thanks for taking the time to answer. However, exclamations of how easy and simple something is 5 years after the question was asked generally indicate that it likely wasn't 5 years ago and don't add much to your answer beyond a sense of condescension. – David Jan 15 '21 at 17:03