3

I created an XML file for an AppWidget as shown below.

xml/appwidget_4x1.xml

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="@dimen/AppWidget_4Cell"
    android:minHeight="@dimen/AppWidget_1Cell"
    android:updatePeriodMillis="0"
    android:previewImage="@drawable/appwidget_4x1_preview"
    android:initialLayout="@layout/appwidget_4x1_loading"
    android:resizeMode="horizontal"
    android:minResizeWidth="@dimen/AppWidget_3Cell" />

The problem is in Android 1.6 it apparently doesn't like me using the @dimen statements for the minWidth and minHeight. When this happens and the user drops an AppWidget on the screen it says, "No more room on this home screen." If I use the dimensions explicitly it starts working again.

res/values/dimens.xml (1.6 - 3.2)

<dimen name="AppWidget_1Cell">72dp</dimen>
<dimen name="AppWidget_4Cell">294dp</dimen>

res/values-v14/dimens.xml (4.0+)

<dimen name="AppWidget_1Cell">40dp</dimen>
<dimen name="AppWidget_4Cell">250dp</dimen>

Is this a bug and if so what's the work around for this? I did it this way to follow the recommendations for Ice Cream Sandwich's new widget layout dimensions.

Jeremy Edwards
  • 14,620
  • 17
  • 74
  • 99
  • It seems a bug in 2.1 and lower versions. Have found in LogCat AppWidgetProviderInfo.minWidth = 8324608 and minHeight = 18499130 in my 4x3 appwidget – Jose_GD Jul 01 '13 at 12:26

1 Answers1

3

I just tried that and it happens also to me with Android 1.6. A quick fix is to create different xml folders (one for Android 1.6, and one for the other versions). So, you could have:

xml-v4 (for Android 1.6), containing dimensions as numeric values
xml-v5 (for the rest), containing dimensions as @dimen/..

or, you could have:

xml (for Android 1.6 - 3.2), containing dimensions as numeric values
xml-v14 (for Android 4), containing the new dimensions

What's bad is that you have to duplicate your appwidget providers xml files, but at least it works.

Mmm..I'm thinking about dropping support for Android 1.6.....(right now it's at 1.3%...).

Cheers, Yuvi

http://www.droidahead.com

YuviDroid
  • 1,546
  • 11
  • 12
  • This is what I've done in my project as a workaround. It's a solution but my only differentiator is the dimensions. It's quite annoying. – Jeremy Edwards Dec 26 '11 at 23:55
  • This problem exists even on 2.1-update1. I dont think it is a 1.6 only issue. – dpcbabu Feb 06 '12 at 17:08
  • @dpcbabu yep that's true. So, the second solution works better (i.e. use xml for Android 1.6-3.2, and xml-v14 for Android 4) – YuviDroid Mar 01 '12 at 20:11
  • Confirmed running my app widget (using @dimens in minWidth and minHeight) on Froyo emulator, it works fine. Problem seems to occur in 2.1 and lower versions – Jose_GD Jul 01 '13 at 12:16