0

我正在编写一个 android 应用程序并且遇到重叠视图的问题。我的布局是

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
>
   <TextView  
       ...
   />
   <EditText
       ...
   />
   <Button
       ...
   />
   <Button
       ...
   />
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
   >
   <SurfaceView
       android:id="@+id/surface_view"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
    />
    <CustomView
       android:id="@+id/custom_view"
       android:background="#0000"
       android:layout_alignTop="@id/surface_view"
       android:layout_alignBottom="@id/surface_view"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
    />
    </RelativeLayout>
</LinearLayout>

如您所见,我试图重叠surface_view 和custom_view。屏幕上仅显示 custom_view。如果我先定义 custom_view,然后定义 surface_view,则只显示 surface_view,但调用 custom_view 方法,因为我可以在 adb logcat 中看到日志消息。我是不是错过了什么。

相同的上述布局(重叠)在不同的项目中工作正常。

任何想法都会有所帮助。谢谢。

4

1 回答 1

-1

如您所见,我试图重叠surface_view 和custom_view。屏幕上仅显示 custom_view。如果我先定义 custom_view,然后定义 surface_view,则只显示 surface_view,但调用 custom_view 方法,因为我可以在 adb logcat 中看到日志消息。我是不是错过了什么。

它们都设置为在 X 和 Y 维度中填充父级。而且,它们都设置在父级的左上角。因此,您只会看到第二个。

于 2010-10-23T12:08:12.140 回答