美文网首页Android学习笔记
RemoteViews(1)API简介

RemoteViews(1)API简介

作者: Rock__Lee | 来源:发表于2018-08-01 18:20 被阅读0次
    search4remoteview.jpg

    1. RemoteViews

    RemoteViews 不是View

    public class RemoteViews
    extends Object implements Parcelable, LayoutInflater.Filter
    
    java.lang.Object
       ↳    android.widget.RemoteViews
    

    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.

    RemoteViews 描述了一个可以在其他进程显示的View层级(View层级是通过加载布局文件得到),并提供了一些修改这个View层级的基础操作(setXxx方法)。

    RemoteViews 仅支持有限layoutwidget,而且不支持这些 layoutwidget的子类(这里说的layout泛指容器)

    layout widget
    AdapterViewFlipper AnalogClock
    FrameLayout Chronometer
    GridLayout ImageButton
    GridView ImageView
    LinearLayout ProgressBar
    RelativeLayout TextClock
    StackView TextView
    ViewFlipper Button
    ListView

    2. RemoteViews.RemoteView

    public static abstract @interface RemoteViews.RemoteView
    implements Annotation
    
    android.widget.RemoteViews.RemoteView
    

    This annotation indicates that a subclass of View is allowed to be used with the RemoteViews mechanism

    就是个注解,来标注可以和 RemoteViews 一起用的View

    TextView源码


    TextView.jpg

    SeekBar源码


    SeekBar.jpg

    3. RemoteViewsService

    public abstract class RemoteViewsService
    extends Service
    
    java.lang.Object
       ↳    android.content.Context
           ↳    android.content.ContextWrapper
               ↳    android.app.Service
                   ↳    android.widget.RemoteViewsService
    
    

    The service to be connected to for a remote adapter to request RemoteViews. Users should extend the RemoteViewsService to provide the appropriate RemoteViewsFactory's used to populate the remote collection view (ListView, GridView, etc).

    它继承Service,用来为RemoteViews中的容器View(例如:ListView,GridView,etc)提供adapter适配器。

    public abstract RemoteViewsService.RemoteViewsFactory onGetViewFactory (Intent intent)
    
    1. RemoteViews 调用 setRemoteAdapter(int viewId, Intent intent)
    2. 相当于调用AbsListView.setRemoteViewsAdapter(Intent) [ListView,GridView是AbsListView的直接子类]
    3. 这个Intent是用来指定RemoteViewsService的
    4. 相关数据操作放在RemoteViewsService onGetViewFactory()方法返回的RemoteViewsFactor中


      setRemoteViewsAdapter.jpg

    4. RemoteViewsFactory

    public static interface RemoteViewsService.RemoteViewsFactory
    
    android.widget.RemoteViewsService.RemoteViewsFactory
    

    An interface for an adapter between a remote collection view (ListView, GridView, etc) and the underlying data for that view. The implementor is responsible for making a RemoteView for each item in the data set. This interface is a thin wrapper around Adapter.

    用来为RemoteViews中容器View与数据之间适配的接口,接口的实现类需要为数据集中的每一条数据提供一个RemoteViews 。

    与Adapter中一样含义方法

    getCount()
    getViewTypeCount()
    hasStableIds()

    abstract RemoteViews getLoadingView()
    用来在getViewAt(int position)方法返回真正的 RemoteViews 之前提供一个loading View

    abstract RemoteViews getViewAt(int position)
    返回指定位置的 RemoteViews


    onCreate()
    RemoteViewsFactory 第一次被创建时调用

    onDestroy()
    当最后一个"RemoteViewsAdapter"与RemoteViewsFactory 解绑时调用

    onDataSetChanged()
    通知数据集改变,更新视图

    以上内容来自墙内官网

    相关文章

      网友评论

        本文标题:RemoteViews(1)API简介

        本文链接:https://www.haomeiwen.com/subject/arwrvftx.html