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
我删除或注释掉MainCanvas
main.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
位于顶部MainCanvas
,MainCanvas's
锁定的画布也以某种方式位于AnimationCanvas's
VideoView 画布的顶部。