【发布时间】:2019-11-19 02:45:43
【问题描述】:
最近,我用SurfaceView创建了一个复杂的View,我认为它很复杂。我发现SurfaceView的背景是黑色的,并通过使用SurfaceView.setZOrderOnTop()将其背景更改为透明。但是还有一个问题是Surfaceview 不在视图层次结构后面。 我的目的是让surfaceview变得透明并且在viewhierarchy后面,有什么解决方案吗? 对不起我的英语不好!
像这样的一些 xml 布局代码
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SurfaceViewActivity">
<com.example.testproject.customview.AnimationView
android:id="@+id/animationview"
android:layout_width="400dp"
android:layout_height="400dp"
android:layout_gravity="center"
android:background="@android:color/transparent"
/>
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:background="@null"
android:layout_gravity="center"
android:visibility="visible"
android:src="@drawable/ic_launcher_foreground"
/>
</FrameLayout>
'AnimationView' 是 SurfaceView 的扩展
【问题讨论】:
-
查看这个链接,它可以帮助你:stackoverflow.com/a/7061396/10271334
-
是的,我以前看过这个答案。我使用了 setZOrderMediaOverlay(true) 方法,我可以在 SurfaceView 顶部添加视图,但透明不起作用。
标签: android surfaceview transparent