0

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. My purpose is surfaceview become transparent and behind the viewhierarchy,is there any solutions for this? Sorry for my poor English!

Some xml layout code like this

<?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

Bub
  • 304
  • 2
  • 6
  • Check this link, it can help you: https://stackoverflow.com/a/7061396/10271334 – Jeel Vankhede Nov 19 '19 at 05:20
  • Yes,I saw this answer before. I used setZOrderMediaOverlay(true) method which I can add views on top of the SurfaceView,but transparent is not working. – Bub Nov 19 '19 at 08:19

1 Answers1

0

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.

Bub
  • 304
  • 2
  • 6