重叠视图有问题吗?

时间:2010-10-23 03:18:12

标签: android android-2.2-froyo

我正在编写一个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中看到日志消息。我错过了一些东西。

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

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

1 个答案:

答案 0 :(得分:-1)

  

正如您所看到的,我正在尝试重叠surface_view和custom_view。屏幕上仅显示custom_view。如果我首先定义custom_view然后定义surface_view,那么只显示surface_view但是调用custom_view方法,因为我可以在adb logcat中看到日志消息。我错过了一些东西。

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

相关问题