androidviewflipperandroid-framelayoutoverlapping-matches

Overlapping ViewFlipper with other components


I have a ViewFlipper, a button and a custom view in one layout. I would like button and custom view to be on top of the viewflipper so that they appear in every layout that is included in the viewflipper. However I can't see anything except viewflipper right now. How can I achieve the effect i want?

<?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>

Solution

  • Use a RelativeLayout and reorder the views in your layout as follows:

    <?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>