首页 > 解决方案 > 是否可以在布局中混合使用“SurfaceView”和另一个“View”?

问题描述

我想要一个LinearLayout包含 aSurfaceView和 aView作为我的内容的水平Fragment。假设它们应该覆盖整个屏幕,宽度和高度相同。

当我尝试这个时,我只得到一个SurfaceView覆盖整个屏幕的 a,这让我想知道是否可以混合 aSurfaceView和 another View

有谁知道这是否可能,如果可能,应该怎么做?

我的布局文件:

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

标签: javaandroidsurfaceview

解决方案


现在找到了解决方案!

当我ImageView使用 Android Studio 的图形编辑器在我的布局中添加一个新的时,图像源会加载该app:srcCompat属性。如果我将其替换为android:src,则图像大小正确并且FrameLayout按预期显示。


推荐阅读