Designing the App Widget Layout

App Widgets have specific layout requirements. To begin with, an App Widget is drawn through the RemoteViews interface, which limits the user interface that can be displayed. Next, the App Widget must conform to the size configured in its properties.

A RemoteViews object is used when the actual display of a view will be performed from within another process. This is exactly what happens with an App Widget: It is displayed in the App Widget host process, not the application's main process. RemoteViews objects are limited in the layout and view objects they may use. Some layout and view objects supported within App Widgets include the following:

► LinearLayout

► FrameLayout

► RelativeLayout

► ImageButton

► ProgressBar

► AnalogClock

► Chronometer

Classes extending these controls cannot be used. This means that the design of the layout is very limited. App Widgets are not meant to display much information, though, and the customary way of enhancing the features of an App Widget is to trigger the launch of full activity when more powerful features or complex screens are required. This functionality could be used to draw an entire screen or be limited to just a popup screen. Either way, activities launched from an App Widget no longer carry the limitations that an App Widget has from the required use of a RemoteViews object.

To design a layout for the App Widget, create a new layout file called widget.xml, and place the following code in it:

<?xml version="i.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android' android:layout_width="wrap_content"

android:layout_height="wrap_content" android:id="@+id/widget_view" > <ImageView android:layout_centerInParent="true" android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/widget_image"></ImageView> <TextView android:text="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:id="@+id/widget_nickname"></TextView> <TextView android:text="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:id="@+id/widget_score"></TextView> </RelativeLayout>

0 0

Post a comment