J. Doe
J. Doe

Reputation: 867

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?

Upvotes: 4

Views: 12087

Answers (3)

Mori
Mori

Reputation: 4671

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.

Upvotes: 0

user6264840
user6264840

Reputation:

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

Upvotes: 0

Ken Wolf
Ken Wolf

Reputation: 23279

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.

Upvotes: 7

Related Questions