如何创建幻灯片菜单xamarin mono

问题描述 投票:0回答:1

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

enter image description here

xamarin.android
1个回答
0
投票

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

您应该设置android:layout_gravitytools: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>

您的活动中:

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

效果类似:

enter image description here您也可以参考native android case

© www.soinside.com 2019 - 2024. All rights reserved.