3

myVideoView似乎只有当它是 my 的唯一孩子时才可见FrameLayout。当有第二个孩子时——a SurfaceView(即使VideoView是之后创建的,给它一个更高的z-index)——那么VideoView就不再可见了。

我有 Vitamio 的扩展VideoView

public class AnimationCanvas extends VideoView{
public static AnimationCanvas animationCanvas;
public AnimationCanvas(Context context, AttributeSet attrs){
    super(context, attrs);
    animationCanvas = this;
    setVideoURI(Uri.parse(MainActivity.toRightPath));
    requestFocus();
    start();
    this.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()){
                case MotionEvent.ACTION_UP:
                    System.out.println("UP");
                    setVideoURI(Uri.parse(MainActivity.animationFilePath));
                    requestFocus();
                    start();
                    break;
                case MotionEvent.ACTION_DOWN:
                    System.out.println("Down");
                    break;
            }
            return true;
        }
    });
}

}

这是 main.xml 文件:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <com.temporary.alexcameronelijahapp.gui.MainCanvas
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <com.temporary.alexcameronelijahapp.gui.AnimationCanvas
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</FrameLayout>

AnimationCanvas我删除或注释掉MainCanvasmain.xml 文件的视图(这些行)时,工作正常:

<com.temporary.gui.MainCanvas
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

我的印象是,在 aFrameLayout中,Z 索引是按照它们添加到布局中的顺序分配的(最后一个添加的 z 索引最高)。但是,AnimationCanvas只要MainCanvas也在那里,就不会看到...

有任何想法吗?

编辑:很高兴知道我实际上在我的MainCanvas.

其次,如果我android:background="#000000"在我的 xml 代码中进行设置AnimationCanvas,它会在 上可见MainCanvas,但视频本身仍然不会显示(好像黑色背景以某种方式掩盖了视频?)

编辑#2:我相信我已经找到了问题,但仍然没有解决方案。当我在我的类中注释掉我的绘制方法时MainCanvas,这意味着没有位图被绘制到画布上,那么它AnimationCanvas是可见的。就好像,即使AnimationCanvas位于顶部MainCanvasMainCanvas's锁定的画布也以某种方式位于AnimationCanvas'sVideoView 画布的顶部。

4

1 回答 1

1

SurfaceView在可见性和 z 顺序等方面,其行为与其他小部件不同。有关详细信息,请参阅GL 表面和可见性:消失。最重要的是,他们只是忽略了可见性。另请注意,这VideoView只是 SurfaceView 的另一个示例。

尝试上面帖子中的建议之一。在您的情况下,您也可以尝试使用与SurfaceView绘图和视频相同的目标。

于 2015-07-19T23:40:23.337 回答