前言
记录一下Android中如何把RemoteViews添加到布局中。
记录于此,方便自己查阅。
正文
Android中有一个类虽然名字中带了View,但不是真正的View,那就是RemoteViews。
下面是RemoteViews继承。
public class RemoteViews implements Parcelable, Filter { //略 }
由于RemoteViews不是继承View或ViewGroup,因此不能直接添加,但RemoteViews提供了转换的方法。
public View apply(Context context, ViewGroup parent) { return apply(context, parent, null); }
举个例子
FrameLayout.LayoutParams mLayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); // RemoteViews remoteViews // FrameLayout mMediaLayout mMediaLayout.addView(remoteViews.apply(mContext, mMediaLayout), mLayoutParams);
参考文章
© 版权声明