【问题标题】:VideoView not visible in FrameLayout when placed over a SurfaceView放置在 SurfaceView 上时,VideoView 在 FrameLayout 中不可见
【发布时间】:2015-10-09 00:14:19
【问题描述】:

我的VideoView 似乎只有当它是我的FrameLayout 的唯一孩子时才可见。当有第二个孩子时——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>

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

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

我的印象是,在FrameLayout 中,Z 索引是按照它们添加到布局中的顺序分配的(最后添加的 Z 索引最高)。但是,AnimationCanvas 不可见,只要MainCanvas 也存在...

有什么想法吗?

编辑:很高兴知道我实际上正在我的MainCanvas 实例上绘制许多位图。

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

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

【问题讨论】:

    标签: android android-framelayout vitamio


    【解决方案1】:

    SurfaceView 在可见性和 z 顺序等方面的行为与其他小部件不同。详情请见GL Surface and Visibility: Gone。最重要的是,他们只是忽略了可见性。 另请注意,VideoView 只是 SurfaceView 的另一个示例。

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

    【讨论】:

    • 完全从层次结构中删除视图对我来说非常有效。谢谢。
    猜你喜欢
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多