与其他组件重叠ViewFlipper

时间:2013-10-20 06:14:08

标签: android viewflipper android-framelayout overlapping-matches

我在一个布局中有一个ViewFlipper,一个按钮和一个自定义视图。我希望按钮和自定义视图位于viewflipper的顶部,以便它们出现在viewflipper中包含的每个布局中。但是我现在除了viewflipper之外什么都看不见。我怎样才能达到我想要的效果?

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="fill_parent"
    android:id="@+id/water_room_layout" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

       <com.example.room.CustomView
        android:id="@+id/customView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
       <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        android:text="Button" 
        android:layout_gravity="center_horizontal|bottom"
       />
    <ViewFlipper android:id="@+id/water_room_flipper"
        android:layout_width="fill_parent" android:layout_height="fill_parent">

        <include layout="@layout/water_room_wall1" android:id="@+id/first" />
        <include layout="@layout/water_room_wall2" android:id="@+id/second" />
        <include layout="@layout/water_room_wall3" android:id="@+id/third" />
        <include layout="@layout/water_room_wall4" android:id="@+id/fourth" />
    </ViewFlipper>

</FrameLayout>

1 个答案:

答案 0 :(得分:0)

使用RelativeLayout并按如下方式对布局中的视图重新排序:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
             android:id="@+id/water_room_layout" android:layout_height="fill_parent"
             xmlns:android="http://schemas.android.com/apk/res/android">

    <ViewFlipper android:id="@+id/water_room_flipper"
                 android:layout_width="fill_parent" android:layout_height="fill_parent">

        <include layout="@layout/water_room_wall1" android:id="@+id/first" />
        <include layout="@layout/water_room_wall2" android:id="@+id/second" />
        <include layout="@layout/water_room_wall3" android:id="@+id/third" />
        <include layout="@layout/water_room_wall4" android:id="@+id/fourth" />
    </ViewFlipper>

    <com.example.room.CustomView
            android:id="@+id/customView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button"
            android:layout_gravity="center_horizontal|bottom"
            />   
</RelativeLayout>