Problem with adding Android widget

I'm trying to clone Power Management widgets from Sony Ericsson phones, but I'm having problems with the new ICS firmware for widgets.

I read this article [link below], but I still have problems.

I ran my widgets on GB and it works the way I want (the second is a clone):
http://i.minus.com/iQmbhue0z0jJz.png

But while working in ICS, my widget becomes smaller than the original:
http://i.minus.com/iudmWwv6xBsxA.png

My files:


widget_info.xml (@ xml / widget_info.xml)

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="40.0dip" android:minHeight="40.0dip" android:updatePeriodMillis="0" android:initialLayout="@layout/widget" > </appwidget-provider> 

widget.xml (@ layout / widget.xml)

 <ImageView android:id="@+id/widget1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:contentDescription="@string/app_name" android:src="@drawable/sms_disabled" android:clickable="true" xmlns:android="http://schemas.android.com/apk/res/android" /> 

I already tried putting android:padding="0dp" in ImageView, I already tried putting the layout on widget.xml and then putting android:padding="0dp" , but I still have this problem.

Any suggestions?

+4
source share
1 answer

The widget is smaller on ICS, because Android 4.0 or later will automatically create a margin around the widget (see also the Android Developers API ). This solution creates two xml files; one for ICS or later without additional fields, and one for older versions of Android with an additional margin.

RES / value / dens.xml

 <?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="widget_margin">8dp</dimen> </resources> 

RES / value-V14 / dens.xml

 <?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="widget_margin">0dp</dimen> </resources> 

Then add android:layout_margin="@dimen/widget_margin" to the layout in your widget XML file

However, phones with (some versions?) Samsung Touchwiz Launcher will not apply automatic margin on ICS, so you can also compensate for this. Read more about this in this question: Are widget margins not applied on the ICS phone using the TouchWiz launcher?

+3
source

All Articles