简体   繁体   English

Android:直到屏幕状态更改才出现addContentView()

[英]Android: addContentView() doesn't appear until screen state changes

I am working adding a video on top of a currently running activity. 我正在在当前正在运行的活动之上添加视频。 I have managed to achieve this using the following: 我设法使用以下方法实现了这一点:

this.surface    = new SurfaceView(getApplicationContext());
this.surface.getHolder().addCallback(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.height       = 500;
params.width        = 500;
this.activity.addContentView(surface, params);

I then attach the MediaPlayer to the SurfaceHolder gotten from this.surface. 然后,我将MediaPlayer附加到从this.surface获得的SurfaceHolder。 It works exactly as I need it to, except for one thing: the SurfaceView does not appear on-screen until after the screen state changes. 它完全按照我的需要工作,除了一件事:SurfaceView直到屏幕状态更改后才出现在屏幕上。 I have to turn the screen off in order for the view to be added to the Activity. 我必须关闭屏幕才能将视图添加到“活动”中。 After that, everything works as expected. 之后,一切都会按预期进行。

Anyone have any clue why this is happening? 有人知道为什么会这样吗?

EDIT: Added more info from a comment to Kelvin Trinh. 编辑:添加了更多信息从注释到Kelvin Trinh。

It's an AIR Native Extension to use the native video component. 它是使用本机视频组件的AIR本机扩展。 The AIR application acts as the main activity, although I have no access to layouts or anything like that. AIR应用程序是主要活动,尽管我无权访问布局或类似内容。 this.activity is that main activity, taken from the extension context (how the AIR and Java apps communicate). this.activity是从扩展上下文中获取的主要活动(AIR和Java应用程序如何通信)。 I need the video to show on top of my app, which I have accomplished. 我需要将视频显示在我的应用程序顶部,这已完成。

You didn't provide the class wrapping your code, but I guess it is a view in your main activity. 您没有提供包装代码的类,但是我想它是您主要活动中的一个视图。

this.activity.addContentView(surface, params); denoted that you adding a surface view to your activity while you are on a specific view. 表示您在特定视图上时向活动中添加了表面视图。 This only adds a reference of your surface to the activity's view hierarchy, and it is updated only when the Activity reloads (recreated, restarted or resumed). 这只会将表面的引用添加到活动的视图层次结构中,并且仅在 重新加载活动(重新创建,重新启动或恢复) 才会更新

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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