title: How to center Menu Items of Navigation View in Xamarin?
body: <p>I am using <em>Xamarin</em> (C#) and in my app I have a navigation view with some menu items.</p>
  
  <p>I want to align all of them to the center of the view.</p>
  
  <p>How can I achieve this?</p>
  
  <p>I have already tried with <code>android:layout_gravity="center"</code> and <code>android:gravity="center"</code> but they both didn't work.</p>
  
  <p><img src="https://i.stack.imgur.com/jy5a7.png" alt="screenshot"></p>
  
  <p><a href="https://i.stack.imgur.com/jy5a7.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>main.axml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/drawer_layout"
      android:fitsSystemWindows="true"&gt;
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
          &lt;include
              android:id="@+id/toolbar"
              layout="@layout/toolbar" /&gt;
          &lt;LinearLayout xmlns:tools="http://schemas.android.com/tools"
              android:orientation="vertical"
              android:layout_below="@+id/toolbar"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:id="@+id/main_content"&gt;
              &lt;EditText
                  android:inputType="textPersonName"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/editText1" /&gt;
              &lt;Button
                  android:id="@+id/myButton"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="Play" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/RelativeLayout&gt;
      &lt;android.support.design.widget.NavigationView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          android:layout_marginEnd="-65dp"
          android:layout_marginRight="-65dp"
          android:fitsSystemWindows="true"
          android:id="@+id/nav_view"
          app:menu="@menu/navmenu"
          app:headerLayout="@layout/headerdrawerlayout" /&gt;
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>navmenu.axml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  
    &lt;group android:checkableBehavior="single"&gt;
      &lt;item
          android:id="@+id/nav_item_overview"
          android:title="Play"/&gt;
      &lt;item
          android:id="@+id/nav_item_notifications"
          android:title="Notifications"/&gt;
      &lt;item
          android:id="@+id/nav_item_leaderboard"
          android:title="Leaderboard"/&gt;
      &lt;item
          android:id="@+id/nav_item_profile"
          android:title="My Profile"/&gt;
      &lt;item
          android:id="@+id/nav_item_friends"
          android:title="Friends"/&gt;
      &lt;item
          android:id="@+id/nav_item_createQuestion"
          android:title="Create Question"/&gt;
  
    &lt;/group&gt;
  
    &lt;group android:id="@+id/group_settings_id"
        android:checkableBehavior="single"&gt;
      &lt;item
          android:title="Settings" /&gt;
      &lt;item
          android:title="Log Out" /&gt;
    &lt;/group&gt;
  
  
  &lt;/menu&gt;
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>I have added a ListView to my NavigationView, but I am still not able to center menu items.
  Do you have any idea how it could be solved?</p>
  
  <p>Main.axml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:theme="@style/MyTheme"
      android:id="@+id/drawer_layout"
      android:fitsSystemWindows="true"&gt;
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
          &lt;include
              android:id="@+id/toolbar"
              layout="@layout/toolbar" /&gt;
          &lt;LinearLayout xmlns:tools="http://schemas.android.com/tools"
              android:orientation="vertical"
              android:layout_below="@+id/toolbar"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:id="@+id/main_content"&gt;
              &lt;EditText
                  android:inputType="textPersonName"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/editText1" /&gt;
              &lt;Button
                  android:id="@+id/myButton"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="Play" /&gt;
              &lt;Button
                  android:text="image"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/button1" /&gt;
              &lt;ImageView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@+id/imageView1" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/RelativeLayout&gt;
      &lt;android.support.design.widget.NavigationView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          android:layout_marginEnd="-65dp"
          android:layout_marginRight="-65dp"
          android:fitsSystemWindows="true"
          android:id="@+id/nav_view"&gt;
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_gravity="center"
              android:orientation="vertical"&gt;
              &lt;include
                  layout="@layout/headerdrawerlayout" /&gt;
              &lt;ListView
                  android:id="@+id/list_menu"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:gravity="center"
                  android:choiceMode="singleChoice" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/android.support.design.widget.NavigationView&gt;
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>MainActivity.cs</p>
  
  <pre><code>    protected override void OnCreate(Bundle savedInstanceState)
      {
          base.OnCreate(savedInstanceState);
          SetContentView(Resource.Layout.Main);
  
          drawerLayout = FindViewById&lt;DrawerLayout&gt;(Resource.Id.drawer_layout);
  
          // Initialize toolbar
          var toolbar = FindViewById&lt;Android.Support.V7.Widget.Toolbar&gt;(Resource.Id.toolbar);
          SetSupportActionBar(toolbar);
          SupportActionBar.SetTitle(Resource.String.app_name);
  
          // Attach item selected handler to navigation view
          var navigationView = FindViewById&lt;NavigationView&gt;(Resource.Id.nav_view);
          var navListView = navigationView.FindViewById&lt;ListView&gt;(Resource.Id.list_menu);
          List&lt;string&gt; listItems = new List&lt;string&gt; { "Play", "Notifications", "Leaderboard", "My Profile", "Friends", "Create Question" };
          ArrayAdapter&lt;string&gt; adapter = new ArrayAdapter&lt;string&gt;(this, Android.Resource.Layout.SimpleListItem1, listItems);
          navListView.Adapter = adapter;
  
          //navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;
  
          // Create ActionBarDrawerToggle button and add it to the toolbar
          var drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, Resource.String.app_name, Resource.String.app_name);
          drawerLayout.AddDrawerListener(drawerToggle);
          drawerToggle.SyncState();
  
          // Add close button handler to navigation view
          var navigationCloseButton = navigationView.FindViewById&lt;ImageButton&gt;(Resource.Id.closeButton);
          navigationCloseButton.Click += delegate
          {
              drawerLayout.CloseDrawers();
          };
  
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/j7QwU.png" rel="nofollow noreferrer">Screenshot</a></p>