Aug 23, 2012

Home Screen Widget step-by-step - define widget layout

It's the second step to create Home Screen Widgets.

Refer to the last article to "Define app widget provider in XML". It's specified android:initialLayout="@layout/widget_layout", means we have a xml file named widget_layout.xml in /res/layout/ folder, to define our widget layout.

/res/layout/widget_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/widget_id"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:background="#F06030"
        android:textColor="#101010"
        android:textSize="30sp"
        android:text="id"/>
    <TextView
        android:id="@+id/widget_status"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/background_dark"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        android:text="status"/>
</LinearLayout>

No comments:

Post a Comment

Infolinks In Text Ads