0

I have a ConstraintLayout with 3 views inside.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/localPeerContainer"
    android:layout_width="120dp"
    android:layout_height="180dp"
    android:background="@color/colorPrimary">

        <TextView
            android:id="@+id/localPeerCircleText"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_gravity="center"
            android:background="@drawable/circle_white"
            android:padding="16dp"
            android:text="UU"
            android:textAlignment="center"
            android:textAllCaps="true"
            android:textColor="@color/colorWhite"
            app:autoSizeMaxTextSize="32sp"
            app:autoSizeMinTextSize="12sp"
            app:autoSizeStepGranularity="2sp"
            app:autoSizeTextType="uniform"
            app:layout_constraintBottom_toBottomOf="@+id/localPeerSurfaceView"
            app:layout_constraintEnd_toEndOf="@+id/localPeerSurfaceView"
            app:layout_constraintStart_toStartOf="@+id/localPeerSurfaceView"
            app:layout_constraintTop_toTopOf="@+id/localPeerSurfaceView" />

        <org.webrtc.SurfaceViewRenderer
            android:id="@+id/localPeerSurfaceView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/localPeerHeader" />

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/localPeerHeader"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <ImageView
                android:id="@+id/localPeerSpotLight"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_marginStart="16dp"
                android:background="@drawable/circle_accent"
                android:padding="3dp"
                android:src="@drawable/ic_spot_light"
                android:visibility="visible"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:tint="@color/colorWhite" />

            <ImageView
                android:id="@+id/localPeerExitSpotLight"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="end"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="16dp"
                android:layout_marginBottom="8dp"
                android:background="@drawable/circle_accent"
                android:padding="3dp"
                android:src="@drawable/ic_close_24dp"
                android:visibility="visible"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
        </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

When i run the application, i clearly see the two ImageViews. But after 2-3 seconds that the SurfaceViewRenderer shows my camera preview, the SurfaceViewRenderer is on the Front of every view. How can i prevent that from happening because i want the ImageViews to be on front always!

james04
  • 1,580
  • 2
  • 20
  • 46
  • Replace all _match_parent_ with `0dp` and the appropriate constraints. _match_parent_ should never be used with a direct child of _ConstraintLayout_. Do you see the _TextView_ `localPeerCircleText` on top of the _SurfaceView_ after the _SurfaceView_ displays? – Cheticamp May 31 '21 at 14:13
  • No..i dont see the localPeerCircleText on Top of the SurfaceView. After some research i think that the problem is that you cant put views on top of SurfaceView if they are in the same xml. SurfaceView gets rendered by other thread than UI. Somethink like that happens – james04 May 31 '21 at 14:16
  • Your _SurfaceViewRenderer_ is a custrom _SurfaceView_. Take a look at [this](https://stackoverflow.com/questions/2933882/how-to-draw-an-overlay-on-a-surfaceview-used-by-camera-on-android) if you haven't come across it. – Cheticamp May 31 '21 at 14:29

1 Answers1

0

Use 0dp for the height of SurfaceViewRenderer, currently, its height is set to match_parent. It's taking the whole screen.

Praveen
  • 3,186
  • 2
  • 8
  • 23
  • This is totally irrelevant. I want the ImageViews to be on top of the SurfaceViewRenderer which i also want to fit all the available width and height – james04 May 29 '21 at 20:50
  • Try elevation on images parent layout, `android:elevation="2dp"` see if this works. – Praveen May 29 '21 at 20:59
  • Nop...same results! – james04 May 29 '21 at 21:02
  • Try taking out images from the current constraint layout and remove the constraint layout, and place images inside the outermost constraint layout. – Praveen May 29 '21 at 21:16
  • No...same! I think that because of the latency of the SurfaceView to get something to display, Android framework places the last drawn view on top of everything. But how can i solve that? – james04 May 29 '21 at 21:34