gpt4 book ai didi

android - 当放置在 SurfaceView 上时,VideoView 在 FrameLayout 中不可见

转载 作者:行者123 更新时间:2023-11-29 01:30:25 24 4
gpt4 key购买 nike

我的 VideoView 似乎只有在它是我的 FrameLayout 的唯一子项时才可见。当有第二个 child 时——一个 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 View 时,AnimationCanvas 工作正常(这些行):

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

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

有什么想法吗?

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

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

编辑 #2: 我相信我已经找到了问题,但仍然没有解决方案。当我在我的 MainCanvas 类中注释掉我的绘画方法时,这意味着没有位图被绘制到 Canvas 上,然后 AnimationCanvas 是可见的。就好像,即使 AnimationCanvas 位于 MainCanvas 之上,MainCanvas 的锁定 Canvas 也不知何故位于 之上AnimationCanvas 的 VideoView Canvas 。

最佳答案

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

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

关于android - 当放置在 SurfaceView 上时,VideoView 在 FrameLayout 中不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31506912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com