Skip to content

Commit 2b15c00

Browse files
committed
Update Widget Design guidelines for ICS
Change-Id: I1b7b8f9c091d38ec1400ce3d8b06e644803544de
1 parent e448f55 commit 2b15c00

33 files changed

+284
-187
lines changed

docs/html/guide/guide_toc.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ localized titles are added in the language order specified below.
717717
</ul>
718718
</li>
719719
<li><a href="<?cs var:toroot ?>guide/practices/ui_guidelines/widget_design.html">
720-
<span class="en">App Widget Design</span>
720+
<span class="en">App Widget Design <span class="new">updated</span></span>
721721
</a></li>
722722
<li><a href="<?cs var:toroot ?>guide/practices/ui_guidelines/activity_task_design.html">
723723
<span class="en">Activity and Task Design</span>

docs/html/guide/practices/ui_guidelines/widget_design.jd

Lines changed: 240 additions & 186 deletions
Large diffs are not rendered by default.

docs/html/guide/topics/appwidgets/index.jd

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,49 @@ following layout classes:</p>
327327
<p>Descendants of these classes are not supported.</p>
328328

329329

330+
<h3 id="AddingMargins">Adding margins to App Widgets</h3>
331+
332+
<p>Widgets should not generally extend to screen edges and should not visually be flush with other widgets, so you should add margins on all sides around your widget frame.</p>
333+
334+
<p>As of Android 4.0, app widgets are automatically given padding between the widget frame and the app widget's bounding box to provide better alignment with other widgets and icons on the user's home screen. To take advantage of this strongly recommended behavior, set your application's <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">targetSdkVersion</a> to 14 or greater.</p>
335+
336+
<p>It's easy to write a single layout that has custom margins applied for earlier versions of the platform, and has no extra margins for Android 4.0 and greater:</p>
337+
338+
<ol>
339+
<li>Set your application's <code>targetSdkVersion</code> to 14 or greater.</li>
340+
<li>Create a layout such as the one below, that references a <a href="{@docRoot}guide/topics/resources/more-resources.html#Dimension">dimension resource</a> for its margins:
341+
342+
<pre>
343+
&lt;FrameLayout
344+
android:layout_width="match_parent"
345+
android:layout_height="match_parent"
346+
<strong>android:layout_margin="@dimen/widget_margin"&gt;</strong>
347+
348+
&lt;LinearLayout
349+
android:layout_width="match_parent"
350+
android:layout_height="match_parent"
351+
android:orientation="horizontal"
352+
android:background="@drawable/my_widget_background"&gt;
353+
&hellip;
354+
&lt;/LinearLayout&gt;
355+
356+
&lt;/FrameLayout&gt;
357+
</pre>
358+
359+
</li>
360+
<li>Create two dimensions resources, one in <code>res/values/</code> to provide the pre-Android 4.0 custom margins, and one in <code>res/values-v14/</code> to provide no extra padding for Android 4.0 widgets:
361+
362+
<p><strong>res/values/dimens.xml</strong>:<br>
363+
<pre>&lt;dimen name="widget_margin"&gt;15dp&lt;/dimen&gt;</pre></p>
364+
365+
<p><strong>res/values-v14/dimens.xml</strong>:<br>
366+
<pre>&lt;dimen name="widget_margin"&gt;0dp&lt;/dimen&gt;</pre></p>
367+
</li>
368+
</ol>
369+
370+
<p>Another option is to simply build extra margins into your <a href="{@docRoot}guide/topics/graphics/2d-graphics.html#nine-patch">nine-patch</a> background assets by default, and provide different nine-patches with no margins for API level 14 or later.</p>
371+
372+
330373
<h2 id="AppWidgetProvider">Using the AppWidgetProvider Class</h2>
331374

332375
<div class="sidebox-wrapper">
-3.42 KB
Binary file not shown.
-82.2 KB
Binary file not shown.
-3.68 KB
Binary file not shown.
-188 KB
Binary file not shown.
-4.74 KB
Binary file not shown.
-348 KB
Binary file not shown.
-4.83 KB
Binary file not shown.

0 commit comments

Comments
 (0)