widget

1. AppWidget framework 

    widgets放在桌面,供用户进行交互。我们通过widgets来"窥视"某个完整应用的一些情况。例如开发显示后台音乐的信息的widget。

 

2.用XML来描述widget
如果希望widget在桌面占据的位置为 宽=2*cell, 高=1*cell ,通过以下的公式转换为dip单位:
Minimum
size in dip = (Number of cells * 74dip) - 2dip
宽=146dip, 高=72dip 

 


BroadcastReceiver

RemoteViews 

 

 

步 骤

1.在manifest中声明widget.

   widget由一个AppWidgetProvider(BroadcastReceive的子类)定义,AppWidgetProvider为widget提供了方便的操作。该BroadcastReceive接收PPWIDGET_UPDATE的广播。

   widget的layout,更新频率和AppWidgetProvider类是由AppWidgetProviderInfo 对象来定义,这个对象是由<meta-data>定义。

 <receiver android:name=".WordWidget" android:label="@string/widget_name"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_word" /> </receiver> 

 

2. AppWidgetProviderInfo

 

3. Creating the App Widget Layout

 

A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:

  • FrameLayout
  • LinearLayout
  • RelativeLayout

And the following widget classes:

  • AnalogClock
  • Button
  • Chronometer
  • ImageButton
  • ImageView
  • ProgressBar
  • TextView

Descendants of these classes are not supported.

 

4. AppWidgetProvider 

   such as when the App Widget is updated, deleted, enabled, and disabled. When these broadcast events occur, the AppWidgetProvider receives the following method calls:

   OnUpdate:

你可能感兴趣的:(widget)