2016-01-31 74 views
2

我在Xamarin Forms中有两页使用自定义渲染器在每个页面上显示Android VideoView。第1页上的视频(嵌套在RelativeLayout内)成功播放。当我使用Navigation.PushAsync(Page2);从第1页导航到第2页时,Page1中的VideoView继续与第2页上的视频重叠。Android VideoView重叠

有没有办法强制VideoView尊重其父视图容器的可见性?

的Page1.xaml:

<?xml version="1.0" encoding="utf-8" ?> 
     <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
        x:Class="MyVideoApp.Page1"> 
     <RelativeLayout> 
      <MyVideoView x:Name="vidPlayer" Source="http://...." 
        RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}" 
        RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}" /> 
      </RelativeLayout> 
     </ContentPage> 

Page2.xaml:

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="MyVideoApp.Page2"> 

    <MyVideoView x:Name="vidPlayer" Source="http://...." /> 

</ContentPage> 
+0

我已经尝试使用OnAppearing()和OnDisapearing()在Xamarin窗体页面浏览到第二页,但没有成功,当玩家的知名度,设置为false。 VideoView.setZOrderMediaOverlay(true)VideoView.setTranslationZ() VideoView.setZOrderOnTop()方法也不能解决问题。 – Adam

+0

基于我发现的关于SurfaceView,听起来像是在能见度回来时摧毁和创建它,这将是要走的路,但不知道这完全是什么样子。 – Adam

回答

0

VideoViewSurfaceViewSurfaceView小号Z-次序被附着到窗口前被确定之后不能更改。所以你不能有多个SurfaceView s同时显示,因为SurfaceView种类通过任何和所有东西显示。

您可能需要尝试完全删除VideoView并稍后重新添加它,或者如果其他所有操作都失败,则可以尝试将VideoView移出屏幕。

Source

+0

有趣的想法。我尝试将它包装在Xamarin Forms框架中,然后在OnDisappear()中将其删除。除第1页上的所有其他元素外,第1页中的所有其他元素仍在显示,这些工作仍在显示。表单导航在尝试在单个活动中分层显示新屏幕时,不能像相对布局那样。 – Adam