如何创建幻灯片菜单xamarin mono

时间:2020-04-17 15:58:40

标签: xamarin.android

如何创建类似于图片的下拉菜单

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以查看DrawerLayout,将菜单设置为从右到左打开。

您应设置1android:layout_gravity例如:

tools:openDrawer="end"

您的活动中:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/drawer_layout"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:fitsSystemWindows="true"
   android:layout_gravity="right"
   tools:openDrawer="end">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="right|end"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

效果如下:

enter image description here

您还可以参考native android case

更新

DrawerLayout drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
        if(drawer.IsDrawerOpen(GravityCompat.End))
        {
            drawer.CloseDrawer(GravityCompat.End);
        }
        else
        {
            base.OnBackPressed();
        }

效果:

enter image description here