androidandroid-viewpagerandroid-framelayoutmapfragment

i have created recycleview and framelayout(Mapfragment) with sameview , but framelayout always in front even through its gone


I have added my code which contains Framelayout with mapview dynamic creation and RecyclerView with another layout, I am using this as a Fragment in ViewPager fragmentstate adapter.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <RelativeLayout
        android:id="@+id/list_item"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">  
        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:elevation="5dp"
            android:id="@+id/rv"
            android:layout_above="@+id/custom_progress1"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />    
    </RelativeLayout>
    <LinearLayout
        android:id="@+id/mapLayout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"> 
        <FrameLayout
            android:id="@+id/mapContainer"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/> 
    </LinearLayout> 
</RelativeLayout>

Solution

  • Its better to have single parent layout which helps in faster UI rendering. You can use something like

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:elevation="5dp" />
    
        <FrameLayout
            android:id="@+id/mapContainer"
            android:layout_width="match_parent"
            android:layout_below="@+id/rv"
            android:layout_height="match_parent" />
    </RelativeLayout>