Android SurfaceView内部对话框(或具有Theme.Dialog的活动)存在布局故障

Android SurfaceView内部对话框(或具有Theme.Dialog的活动)存在布局故障,android,layout,dialog,surfaceview,visual-glitch,Android,Layout,Dialog,Surfaceview,Visual Glitch,我试图在活动中显示表面视图,该活动的主题扩展了主题。对话框(您可以认为我试图在对话框类中显示它),但我遇到了一些布局问题 我无法拍摄照片,因为在拍摄截图时小故障消失了:/但是不管怎样,你看到的是SurfaceView的“洞”从其原始位置移动,并产生了一些奇怪的叠加效果 问题似乎与标志windowIsFloating有关,如果我将其设置为false,故障就会消失 有没有办法找到一种可能的解决办法,继续使用windowIsFloating标志 复制问题的简单布局: <?xml version

我试图在
活动
中显示
表面视图
,该活动的主题扩展了
主题。对话框
(您可以认为我试图在
对话框
类中显示它),但我遇到了一些布局问题

我无法拍摄照片,因为在拍摄截图时小故障消失了:/但是不管怎样,你看到的是
SurfaceView
的“洞”从其原始位置移动,并产生了一些奇怪的叠加效果

问题似乎与标志
windowIsFloating
有关,如果我将其设置为false,故障就会消失

有没有办法找到一种可能的解决办法,继续使用
windowIsFloating
标志


复制问题的简单布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#fff">

<FrameLayout android:id="@+id/container"
             android:layout_width="250dp"
             android:layout_height="250dp"
             android:layout_centerInParent="true"
             android:padding="30dp"
             android:background="#ff0">

    <SurfaceView android:id="@+id/surface"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent" />

</FrameLayout>
<style name="MyTheme" parent="@android:style/Theme">
    <item name="android:windowIsFloating">true</item>
</style>

并修改活动的主题,如下所示,以重现该问题:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#fff">

<FrameLayout android:id="@+id/container"
             android:layout_width="250dp"
             android:layout_height="250dp"
             android:layout_centerInParent="true"
             android:padding="30dp"
             android:background="#ff0">

    <SurfaceView android:id="@+id/surface"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent" />

</FrameLayout>
<style name="MyTheme" parent="@android:style/Theme">
    <item name="android:windowIsFloating">true</item>
</style>

真的

似乎没有办法解决这个问题,简单地说,
窗口是浮动的
标志与
SurfaceView
非常不协调

因此,根据这里的答案,我最终创建了一个主题,该主题扩展了Dialog的主题,但将
windowIsFloating
标志设置为
false
,将
windowIsTranslucent
设置为
true

这样,您需要手动创建一个类似对话框的布局,但您没有任何问题,并且您的背景可以完全透明:)


主题的同音示例将实现此技巧:

<style name="MyTheme" parent="@android:style/Theme">
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowIsTranslucent">true</item>
</style>

假的
真的

然后,您需要在布局中应用页边距,否则它将作为一项正常活动全屏显示。

我分享这一点,因为它可能对其他人有用。我遇到了一个透明度问题,对话框中有一个SurfaceView,下面的答案帮助我解决了这个问题(我不必像这里建议的那样使用windowIsFloating=false,尽管它也能解决这个问题):

事实证明,我的问题既是一个Z排序问题,也是一个透明度问题