简体   繁体   English

如何使 SurfaceView 透明并位于 ViewHierarchy 后面

[英]How to make SurfaceView transparent and behind the ViewHierarchy

Recently,I use SurfaceView to create a complex View which I think it is complex.I found that SurfaceView's background is black,and change its background to transparent by using SurfaceView.setZOrderOnTop().But there is another problem is that the Surfaceview is not behind the viewhierarchy.最近,我用SurfaceView创建了一个复杂的View,我觉得很复杂。我发现SurfaceView的背景是黑色的,并通过使用SurfaceView.setZOrderOnTop()将其背景更改为透明。但是还有一个问题是Surfaceview不是观念层次的背后。 My purpose is surfaceview become transparent and behind the viewhierarchy,is there any solutions for this?我的目的是让surfaceview变得透明并且在viewhierarchy后面,有什么解决方案吗? Sorry for my poor English!对不起我的英语不好!

Some xml layout code like this像这样的一些 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' is extends SurfaceView 'AnimationView' 是 SurfaceView 的扩展

I think my start direction was wrong,because android.view.View hardwareAccelerator is open by default,and also I move my code from SurfaceView to android.view.View to test the performance what I found is that the performance is enough, and in conclusion.I didn't find the method to solve this problem but change a way to solve this.我认为我的开始方向是错误的,因为 android.view.View hardwareAccelerator 默认是打开的,并且我将我的代码从 SurfaceView 移动到 android.view.View 以测试性能我发现性能足够了,并且在结论。我没有找到解决这个问题的方法,而是换了一个方法来解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM