Search code examples
androidxamarin.androidmvvmcross

Overlay Toolbar over MvxExpandableListView


The toolbar in my axml file is made visible/invisible by toggling the button. The data is displayed in MvxExpandableListView. Once the list view appears, the toolbar comes at the back. How to set the toolbar to front always, from axml or Viewmodel?

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/ListViewRelativeLayout">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        local:MvxBind="Visible IsNotificationBarVisible">
        <ImageView/>
        <LinearLayout>
        <TextView/>
        <TextView/>
        </LinearLayout>
        <ImageView/>
    </android.support.v7.widget.Toolbar>
    </RelativeLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
android:id="@+id/ListViewRelativeLayout">
        <TextView/>
        <MvxExpandableListView />
    </LinearLayout>

</RelativeLayout>

Solution

  • You are over complicating your layout a lot. If you just need to overlay views on top of each other, you can use a FrameLayout. The last defined view in the FrameLayout will be on top. So something like:

    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:local="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <MvxExpandableListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            ... />
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            local:MvxBind="Visible IsNotificationBarVisible">
    </FrameLayout>