我希望包含LinearLayout
和SurfaceView
的水平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>
这是因为您给了SurfaceView
全部权重,却忘记赋予1
任何权重。 FrameLayout
和FrameLayout
视图均应具有以下内容:
SurfaceView
使它们大小相等。
现在发现问题!
[当我使用Android Studio的图形编辑器在布局中添加新的android:layout_width="0dp"
android:layout_weight="1"
时,图像源会加载ImageView
属性。如果我将其替换为app:srcCompat
,则图像尺寸正确,并且android:src
出现预期的样子。