[英]Can I dynamically add a View to home screen widget?
I am writing a home screen widget. 我正在写一个主屏幕小部件。 Is it possible to add a View, eg ImageView, to a home screen widget through RemoteViews?
是否可以通过RemoteViews将View(例如ImageView)添加到主屏幕小部件? I want to generate the views for the home screen widget dynamically.
我想动态生成主屏幕小部件的视图。
Thanks. 谢谢。
updateViews = new RemoteViews(context.getPackageName(), R.layout.widget_news);
updateViews.setTextViewText(R.id.widget_title, mTitle);
updateViews.setImageViewBitmap(R.id.widget_picture,
BitmapFactory.decodeByteArray(image, 0, image.length));
My code is like above. 我的代码就像上面一样。 But when I call
updateViews.addView(aView)
, my IDE didn't allow me to do that and give me an compile error. 但是当我调用
updateViews.addView(aView)
,我的IDE不允许我这样做并给我一个编译错误。
Every time you use RemoteViews
, you are pushing the definition of your UI to the app widget. 每次使用
RemoteViews
,都会将UI的定义推送到app小部件。 You want more Views
? 你想要更多的
Views
? Just use an appropriate layout at that point when creating the RemoteViews
instance. 在创建
RemoteViews
实例时,只需使用适当的布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.