将RemoteView转换为视图 [英] Converting RemoteView into a View

查看:78
本文介绍了将RemoteView转换为视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试将RemoteViews实例呈现到Canvas上,就像我对常规View所做的那样.我用

I am trying to render a RemoteViews instance onto a Canvas, like I do with a regular View. I use

RemoteViews.apply(上下文,null)

RemoteViews.apply(context, null)

并返回一个嵌套了所有视图并正确测量(位置和大小正确)的FrameLayout,但是在返回的视图上使用.draw之后,它将呈现所有没有值的元素-TextViews为空,AnalogClock重置在00:00等.

and it returns a FrameLayout with all the views nested and properly measured (location and size is correct,) but after using .draw on the returned view, it renders all elements with no values -- TextViews are empty, AnalogClock is reset at 00:00 and so on.

有什么想法吗?我迷路了:(

Any ideas? I'm lost :(

推荐答案

不确定问题是否仍然存在.不过,这是我对RemoveViews的经验.看来您不能只在返回的视图上调用draw().您必须将此视图添加到父容器中,以使其成为全局视图层次结构的一部分.例如,您有一个带有单个FrameLayoutActivity.您的代码将如下所示.

Not sure if the question is still actual. Nevertheless here is my experience with RemoveViews. It appears you cannot just call draw() on the returned view. You have to add this view to a parent container to make it a part of global view hierarchy. For instance, you have an Activity with a single FrameLayout in it. Your code will look like this.

FrameLayout parent = findViewById(R.id.container);
View view = RemoteViews.apply(getActivity(), parent);
parent.addView(view);

现在,您应该可以看到测试了.如果您设置了侦听器,它们也将正常工作.

Now you should be able to see tests. If you set listeners, they will work properly too.

这篇关于将RemoteView转换为视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆