是否可以在布局中混合使用一个SurfaceView和另一个View?

问题描述 投票:0回答:2

我希望包含LinearLayoutSurfaceView的水平View作为我的Fragment的内容。假设它们应该覆盖整个屏幕,并且宽度和高度均应相等。

[尝试此操作时,我只得到覆盖整个屏幕的SurfaceView,这使我想知道是否可以将SurfaceView和另一个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>

java android surfaceview
2个回答
0
投票

这是因为您给了SurfaceView全部权重,却忘记赋予1任何权重。 FrameLayoutFrameLayout视图均应具有以下内容:

SurfaceView

使它们大小相等。


0
投票

现在发现问题!

[当我使用Android Studio的图形编辑器在布局中添加新的android:layout_width="0dp" android:layout_weight="1" 时,图像源会加载ImageView属性。如果我将其替换为app:srcCompat,则图像尺寸正确,并且android:src出现预期的样子。

© www.soinside.com 2019 - 2024. All rights reserved.