【发布时间】:2023-03-12 11:07:02
【问题描述】:
我有一个绘制 HUD 的自定义视图:
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<VideoView
android:id="@+id/videoView1"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.widgets.HUD
android:id="@+id/hud"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.hud_fragment, container, false);
frameLayout = (FrameLayout) view.findViewById(R.id.frameLayout);
hudWidget = (HUD) view.findViewById(R.id.hudWidget);
videoView = (VideoView) view.findViewById(R.id.videoView1);
videoView.setVideoURI(Uri.parse("http://88.150.210.138:5001/spor"));
videoView.start();
frameLayout.removeView(hudWidget);
frameLayout.addView(hudWidget);
hudWidget.bringToFront();
return view;
}
视频一开始播放,我就在我的 VideoView 上播放 RTSP 流,它看起来像这样:
如何强制 HUD 在 VideoView 上绘制? HUD extends SurfaceView
项目
我正在尝试添加 VideoView 的项目是DroidPlanner 您可以尝试克隆并查看问题。 (需要手动添加 VideoView,因为它不在 repo 中)。
【问题讨论】:
-
如果您的小部件扩展了 View,您是否尝试过
view.bringtoFront()。您的布局定义似乎正确。 -
@Slartibartfast 试过了,检查我的更新。还是一样。
-
我试图重新创建您的问题,但实际上失败了。这是我制作的项目:github.com/andrask/androidhud 它重现了您使用视频视图、按钮和自定义视图创建的相同类型的界面。视频开始时,所有元素都停留在顶部,没有任何反应。唯一的区别是它不使用片段。您是否尝试过使用单个活动或静态链接片段?
-
你能告诉我结果吗:adb shell dumpsys SurfaceFlinger
-
@allprog 我的 HUD 视图是 SurfaceView 也许是这样?您需要将
com1的文件夹名称更改为com,这会导致Windows 上的Git 出现路径问题。
标签: android video-streaming android-videoview rtsp ondraw