1.RemoteView概述android
到目前爲止,我發現RemoteView會用在兩個地方:一個是在AppWidget,另一個是在Notification.
先從官方對他的定義來看:
RemoteView--
A class that describes a view hierarchy that can be displayed in another process. The hierarchy is inflated from a layout resource file, and this class provides some basic operations for modifying the content of the inflated hierarchy.
RemoteView描述一個view,而這個view是在另一個進程顯示的。它inflate於layout資源文件。而且提供了能夠修改過view內容的一些簡單基礎的操做。
從這個定義咱們就知道RemoteView是用來描述一個垮進程顯示的view。從而你就會明白爲何AppWidget和Nofication須要用到它了。
1,AppWidget---RemoteView
咱們都知道AppWidgetProvider是一個BrocaseReceiver,只是接受到Enable, Update,disale,delete這些message,而真正顯示界面的是AppWidgetHostView(這是在Launcher裏面實現的)這中間就是經過RemoteView來溝通。經過RemoteView告訴Launcher你想要的AppWidget是長什麼樣。
2,Notification--RemoteView
若你想自定義你的Notification也必須經過RemoteView.由於你定義的Nofication和顯示Notification也是兩個不一樣的進程。
在android 2.2以前,RemoteView只支持一些簡單的view:TextView, Framelaout..不支持ListView和GridView等複雜的view,它的操做也是簡單的click。在網上有人說是經過@RemoteView這個標籤肯定RemoteView是否支持view.在view的源文件加上@RemoteView這個標籤就能夠支持了。這個我尚未去試試過。 (在htc sence ui 中咱們能夠看到有用到listview,gridview,這是怎麼作到的呢,看下面說明)
在android 3.0,Google增強這方面,下面來源官方文檔:
Expanded Home screen widgets
Home screen widgets are popular with users because they offer fast access to application-specific data directly from the home screen. Android 3.0 lets developers take home screen widgets to the next level, offering more types of content and new modes of interaction with users. Developers can now use more standard UI widget types home screen widgets, including widgets that let users flip through collections of content as 3D stacks, grids, or lists. Users can interact with the home screen widgets in new ways, such as by using touch gestures to scroll and flip the content displayed in a widget.app