Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

android - Appwidget size calculation

It might be me, but when I calculate minimum app widget sizes according to the formula given on the android page I don't get the right widget widths; The formula is as follows:

width(n) = (70 x n) - 30

When I want to have a 5x1 widget, the correct width would be (5 * 70) - 30 = 320dp. However when testing this on a motorola Xoom it resolves to being a 4x1 widget. I've tested different values and 400dp seems good for 5x1 on the motorola xoom with Honeycomb, but then I'd test it on a regular Galaxy Tab with Gingerbread and then it resolves to a 6x1 (like one would expect).

So two questions here;

  • What difference between Gingerbread and Honeycomb am I overlooking?
  • Since I know ICS widget size no longer has padding between widgets, is there some rule of thumb here as well?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In my 4x1 widget, I used these dimensions for res/values/dimens.xml:

<!-- size = (74 x n) - 2 -->
<dimen name="appwidget_margin">0dp</dimen>
<dimen name="appwidget_min_width">294dp</dimen>
<dimen name="appwidget_min_height">72dp</dimen>

and for res/values-v14/dimens.xml:

<!-- size = (70 x n) - 30 -->
<dimen name="appwidget_margin">0dp</dimen>
<dimen name="appwidget_min_width">250dp</dimen>
<dimen name="appwidget_min_height">40dp</dimen>

I used widget templates pack for background images .

In official guide there is written that default margin in res/values/dimens.xml should be 8dp, but if I use 8dp, my widget is smaller than standard widgets on the desktop (google search, weather etc.). Thats's because margin for v1-v13 is built in the background image:

enter image description here

I tested it on HTC Desire, Nexus S, emulator Android 2.2 and emulator Android 2.3.3. With the templates pack backgrounds and configuration above, my widget's size is the same as other standard widgets and looks good on all devices I tested.

There is also problem with various launchers. I recommend this article to read: http://radleymarx.com/blog/app-widget-padding-margins-in-ics-android/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...