2017-03-18 21 views
1

VideoViewを背面から前面に持ってきようとしていますが、何も問題ありません。以下では、まずコードを提示してから、私が試したことを提示し、誰かが私の問題を解決できることを願っています:Android VideoView BringToFrontがXamarinで2回目に動作しません

これはXamarinを使って書かれた簡単なレトロアプリです。

さらに騒ぎがなければ、ここに私のコードは次のとおりです。

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(); 

     } 
    } 
} 

プライバシーの理由 - 実際の動画のURLに置き換えられます「...」、mp4ファイルを提供することができます任意のURLが動作します。ここ

そして、私は完全にbackViewを閉塞するforeViewを有することが意図活動

<?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> 

に関連したレイアウトで、この例では、しかし、私は意図的に表示する右には50pxでforeViewをシフトの効果。

フル、実行可能なXamarinのソリューションは、我々はプログラムを実行すると、それは最初foreView上のビデオを再生します私のGitHub repository

で見つけることができ、完了時に、それが完了すると、backView上のビデオを再生しますforeViewをもう一度起動してforeViewを再生しようとしますが、backViewを隠蔽することはなく、backViewはfrontViewを閉塞します。

は、上記の問題を説明し、ここで私が試みたものです:

foreView.Invalidate() does not work. 
foreView.RequestLayout() does not work. 
foreView.Parent.RequestLayout() does not work. 

問題は素晴らしいだろう修正プルリクエストを、事前にどうもありがとう!

答えて

0

VideoViewを前面に持っていく方法を試しましたが、あなたの言ったように機能しません。

しかし、VideoViewのZオーダーのレベルは加算の順序に依存します。

だから、回避策として、私は2つのVideoViewの添加の順序を変更:

private void OnForeViewCompleted1() 
    { 
     //backView.BringToFront(); 
     //backView.SetZOrderOnTop(true); 
     //myfatherLayout.UpdateViewLayout(backView, backView.LayoutParameters); 
     myfatherLayout.RemoveView(foreView); 
     myfatherLayout.AddView(foreView); 
     img1.BringToFront(); 
     this.backView.Start(); 
    } 

    private void OnBackViewCompleted1() 
    { 
     //foreView.BringToFront(); 
     // foreView.SetZOrderOnTop(true); 
     //myfatherLayout.UpdateViewLayout(foreView, foreView.LayoutParameters); 
     myfatherLayout.RemoveView(backView); 
     myfatherLayout.AddView(backView); 
     img2.BringToFront(); 
     this.foreView.Start(); 
    } 

myfatherLayoutはビデオビューコンテナ(あなたRelativeLayout)です。あなたは、ビデオ・ビューはあなたの条件として表示されます見ることができます

enter image description here

関連する問題