簡體   English   中英

如何使 SurfaceView 透明並位於 ViewHierarchy 后面

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

最近,我用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 的擴展

我認為我的開始方向是錯誤的,因為 android.view.View hardwareAccelerator 默認是打開的,並且我將我的代碼從 SurfaceView 移動到 android.view.View 以測試性能我發現性能足夠了,並且在結論。我沒有找到解決這個問題的方法,而是換了一個方法來解決這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM