在 MvxExpandableListView 上覆盖工具栏
Overlay Toolbar over MvxExpandableListView
我的 axml 文件中的工具栏是 visible/invisible 通过切换按钮制作的。数据显示在 MvxExpandableListView 中。一旦列表视图出现,工具栏就会出现在后面。如何从 axml 或 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>
您的布局过于复杂了。如果您只需要将视图相互叠加,您可以使用 FrameLayout
。 FrameLayout
中最后定义的视图将位于顶部。所以像:
<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>
我的 axml 文件中的工具栏是 visible/invisible 通过切换按钮制作的。数据显示在 MvxExpandableListView 中。一旦列表视图出现,工具栏就会出现在后面。如何从 axml 或 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>
您的布局过于复杂了。如果您只需要将视图相互叠加,您可以使用 FrameLayout
。 FrameLayout
中最后定义的视图将位于顶部。所以像:
<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>