A
A
Artem2015-01-26 11:54:42
Android
Artem, 2015-01-26 11:54:42

How to correctly set the size of the widget?

I need to make a 4x1 cell widget. For this I use a simple code:

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="250dp"
    android:minHeight="40dip"
    android:updatePeriodMillis="0"
    android:initialLayout="@layout/widget"
    android:configure="ru.bartwell.myapp.WidgetActivity" />

I'm testing it on two Genymotion virtual devices:
  1. Google Nexus 7, 800x1280, Android
  2. 4.4.4 Samsung Galaxy S5, 1080x1920, Android 4.4.4

And I get two different results:
With android:minWidth="250dp" and android:minHeight="40dip" (new formula):
  1. Google Nexus 7 - 3x1
  2. Samsung Galaxy S5 - 4x1

With android:minWidth="292dp" and android:minHeight="70dip" (old formula):
  1. Google Nexus 7 - 4x1
  2. Samsung Galaxy S5 - 4x2

As you can see, the size of the widget depends on the screen resolution and is calculated incorrectly anyway (either 3x1 or 4x2). So what is the right way to set the size of the widget?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question