Search code examples
javaandroidsurfaceview

Is it possible to mix a `SurfaceView` and another `View`s in a layout?


I would like to have a horizontal LinearLayout containing a SurfaceView and a View as the content of my Fragment. Let's say they should cover the whole screen, be equally sized in width and height.

When I try this, I only get a SurfaceView which covers the whole screen, which makes me wonder if it is possible to mix a SurfaceView and another View.

Does anyone know if it is possible and, if possible, how it should be done?

My layout file :

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="horizontal">

    <SurfaceView
        android:id="@+id/SurfaceView"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:padding="5dp"></SurfaceView>

    <FrameLayout
        android:id="@+id/AV"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        tools:visibility="visible">

        <ImageView
            android:id="@+id/FAV"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal"
            app:srcCompat="@drawable/fond_vertical" />

        <ImageView
            android:id="@+id/CV"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            app:srcCompat="@drawable/curseur" />
    </FrameLayout>

</LinearLayout>


Solution

  • The solution is now found!

    When I add a new ImageView in my layout with the Android Studio's graphical editor, the image source is loaded with the app:srcCompat attribute. If I replace it with android:src, the image is correctly sized and the FrameLayout appears as expected.