N Czar N Czar - 19 days ago 6
Android Question

How do i make Recyclerview appear on top of mapview

I have a recycler view which appears when users enter something on a textbox in my Android app. I also have a mapview just below the textbox but when the recycler view appears it goes behind the mapview. I want the recycler view to appear on top of the mapview.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
>


<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="@color/colorPrimaryDark"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_width="match_parent"
android:layout_height="50dp">
</android.support.v7.widget.Toolbar>

<Chronometer
android:layout_marginTop = "450dp"
android:id="@+id/chronometer"
android:format="%s"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textSize="30sp"
android:includeFontPadding="false"/>

<TextView
android:id="@+id/text_id"
android:layout_marginTop= "450dp"
android:layout_width="100dp"
android:layout_marginLeft ="20dp"
android:layout_marginStart ="20dp"
android:layout_height="wrap_content"
android:text="Trip Distance"
android:textColor="@android:color/holo_blue_dark"
android:textColorHighlight="@android:color/primary_text_dark"
android:textSize="25dp"/>

<Button
android:layout_marginTop = "380dp"
android:layout_marginLeft ="20dp"
android:layout_marginStart ="20dp"
android:layout_height="60dp"
android:layout_width="100dp"
android:text="@string/self_destruct"
android:id="@+id/self_destruct"
android:onClick="selfDestruct"
android:layout_marginBottom = "10dp"
android:background="@drawable/bg_button"
android:textSize="15sp"
android:textColor="@android:color/white" />

<Button
android:layout_marginTop = "380dp"
android:layout_marginRight ="20dp"
android:layout_marginEnd ="20dp"
android:layout_width="100dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:text="@string/trip_details"
android:id="@+id/trip_details"
android:onClick="sendTripdetails"
android:background="@drawable/bg_button"
android:textSize="15sp"
android:textColor="@android:color/white" />

<Button
android:layout_marginTop = "60dp"
android:layout_marginRight ="20dp"
android:layout_marginEnd ="20dp"
android:layout_width="80dp"
android:layout_height="50dp"

android:text="@string/share_trip"
android:id="@+id/share_trip"
android:onClick="ShareTrip"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="@drawable/bg_button"
android:textSize="12sp"
android:textColor="@android:color/white" />

<Button
android:layout_marginTop = "60dp"
android:layout_marginRight ="20dp"
android:layout_marginEnd ="20dp"
android:layout_width="80dp"
android:layout_height="50dp"
android:text="@string/pick_contact"
android:id="@+id/pickcontact"
android:onClick="ShareTrip"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="@drawable/bg_button"
android:textSize="12sp"
android:textColor="@android:color/white" />

<Button
android:layout_marginTop = "60dp"
android:layout_marginRight ="20dp"
android:layout_marginEnd ="20dp"
android:layout_width="80dp"
android:layout_height="50dp"
android:text="@string/send_sms"
android:id="@+id/sendsms"
android:onClick="ShareTrip"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="@drawable/bg_button"
android:textSize="12sp"
android:textColor="@android:color/white" />

<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>

<EditText
android:id="@+id/search_box"
android:layout_width="240dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="60dp"
android:layout_marginBottom="8dp"
android:paddingLeft="8dp"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:textSize="14sp"
android:hint="@string/search_hint"
android:background="@drawable/bottom_border"
/>



<android.support.v7.widget.RecyclerView
android:id="@+id/myrecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_marginTop="90dp"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:scrollbars="vertical" />

<com.mapbox.mapboxsdk.maps.MapView

android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_marginTop="120dp"
android:layout_gravity="center_horizontal|bottom"
android:layout_height="240dp" />

<Button
android:id="@+id/clear_txt"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="70dp"
android:layout_marginEnd="120dp"
android:layout_marginRight="40dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="@android:drawable/ic_menu_close_clear_cancel" />

<TextView
android:id="@+id/text_1"
android:layout_marginLeft= "25dp"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginTop="10dp"
android:textColor="@android:color/black"
android:textColorHighlight="@android:color/primary_text_dark"
android:layout_centerHorizontal="true"
android:textSize="18dp"/>

<com.example.docuwind.maplive.RoundedImageView

android:id="@+id/imageView_round"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="0dp"
android:layout_marginRight="50dp"
android:layout_marginEnd="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerHorizontal="true"
/>

</RelativeLayout>

Answer

Views which placed first in RelativeLayout ViewGroup will draw first on UI, so interchange the order of your views can solve your problem.

<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.mapbox.mapboxsdk.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_marginTop="120dp"
    android:layout_gravity="center_horizontal|bottom"
    android:layout_height="240dp" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/myrecyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_marginTop="90dp"
    android:layout_marginStart="20dp"
    android:layout_marginLeft="20dp"
    android:scrollbars="vertical" />
</RelativeLayout>