简体   繁体   English

我可以动态地将视图添加到主屏幕小部件吗?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM