【发布时间】:2018-05-22 19:09:17
【问题描述】:
好的,我已经在 SO 和网络上解决了许多类似的问题,但无济于事。 我只是想在 SurfaceView 上覆盖一个透明视图.. 并最终在其上绘制一个矩形,使其看起来覆盖了相机预览。
我无法让自定义视图透明,它会挡住底层的相机预览。有什么建议吗?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="400dip">
<SurfaceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/drawSurface" />
<com.bobby.facecapture.FaceOverlayView
android:id="@+id/drawOverlay"
android:background="@android:color/transparent"
android:layout_width="200dip"
android:layout_height="200dip"
/>
</FrameLayout>
</RelativeLayout>
200x200 只是暂时的,以证明它确实覆盖了另一个视图。
FaceOverlayView 只是一个自定义视图 - 直接从 View 派生,没有覆盖任何东西(目前)。
我在相机预览顶部看到一个黑色矩形
【问题讨论】:
-
我们在我们的一个应用程序中使用了非常相似的设置,它似乎工作正常 - 尝试在您的自定义视图中覆盖
onDraw方法,并且在其中完全不做任何事情(不要调用 @987654323 @),这有什么改善吗? -
感谢您的建议,但不,我仍然只是在顶部看到黑色视图。我尝试在构造函数和 XML 声明中将背景颜色设置为透明。现在在派生视图中除了构造函数和空的 onDraw 什么都没有。
-
这可能看起来有点矫枉过正,但也许将透明图片设置为背景会起作用?
-
同样的结果——我什至尝试在顶部添加一个带有透明 png 的普通 ImageView——但它仍然使所有内容都变黑。
标签: android