Search code examples
androidwidgetsizedefault-value

Change default widget size


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?


Solution

  • 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 and minHeight 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.