我试图将VideoView从背面带到前面,但没有任何工作。在下面,我将首先介绍代码,然后我将介绍我尝试的内容,并希望有人能够解决我的问题:Android VideoView BringToFront在Xamarin中不能正常工作
这是使用Xamarin编写的Android应用程序的简化版本。
事不宜迟,这里是我的代码:
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Media;
using System;
namespace Experiment
{
public class Listener : Java.Lang.Object, MediaPlayer.IOnCompletionListener
{
private Action action;
public Listener(Action action)
{
this.action = action;
}
public void OnCompletion(MediaPlayer unused)
{
this.action();
}
}
[Activity(Label = "Experiment", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : Activity
{
private VideoView foreView;
private VideoView backView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
this.foreView = this.FindViewById<VideoView>(Resource.Id.foreView);
this.backView = this.FindViewById<VideoView>(Resource.Id.backView);
this.foreView.SetVideoURI(Android.Net.Uri.Parse("..."));
this.foreView.Start();
this.foreView.SetOnCompletionListener(new Listener(this.OnForeViewCompleted1));
this.backView.SetVideoURI(Android.Net.Uri.Parse("..."));
this.backView.SetOnCompletionListener(new Listener(this.OnBackViewCompleted1));
}
private void OnForeViewCompleted1()
{
this.backView.Start();
this.foreView.SetVideoURI(Android.Net.Uri.Parse("..."));
this.backView.BringToFront();
}
private void OnBackViewCompleted1()
{
this.foreView.SetOnCompletionListener(null);
this.foreView.Start();
this.foreView.BringToFront();
}
}
}
出于保护隐私的原因 - 实际视频网址被替换成“...”,这可以起到MP4文件将工作的任何URL。
这里是与活动
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/backView"
android:layout_width="200px"
android:layout_height="200px"
android:layout_marginTop="0px"
android:layout_marginLeft="0px" />
<VideoView
android:id="@+id/foreView"
android:layout_width="200px"
android:layout_height="200px"
android:layout_marginTop="0px"
android:layout_marginLeft="50px" />
</RelativeLayout>
相关联的布局我打算有foreView完全闭塞backView,在这个例子中,然而,我故意foreView 50像素转移到以显示正确的效果。
完整的,可运行Xamarin的解决方案可以在我的GitHub repository
当我们运行程序时,它首先会起到对foreView的视频,在建成后,将发挥对backView视频可以发现,在完成它试图再次调用foreView并播放foreView,但它不会显示出来遮挡backView,而是backView遮挡了frontView,这是我需要解决的问题。
上述问题,这里是我尝试:
foreView.Invalidate() does not work.
foreView.RequestLayout() does not work.
foreView.Parent.RequestLayout() does not work.
上拉请求解决这一问题将是真棒,非常感谢事先!