###前提・実現したいこと
タブレット(SM-T800)で使えるようにアプリをVisualStudio2015でxamarinを導入し、c#で制作しています。
新規作成から「Android Navigation Drawer App AppCompat」を選択し、タブレット用にレイアウトを追加した以外はそのままの状態です。
デフォルトでデバッグすると画面左端からスワイプすることでナビゲーションメニューが出てくるのですが、
スワイプの必要なく、最初から表示している状態にしたいのです。
具体的には「Todoist」や「Evernote」みたいな感じです。スマートフォンだとスワイプでメニューが出てきますが、タブレットだと最初から表示されています。
上記画像のようなUIを作りたいのですが、改変する場所の見当がつきません。
タブレットでも今のgoogle playみたいな感じで左から引っ張ってこないとメニューが出ない画面が適用されてしまいます。
最初からメニューを配置させたいのですが、どのようにすればよいでしょうか。
コード(main.axml)
<?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" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- The main content view --> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/toolbar_layout"> <include android:id="@+id/toolbar" layout="@layout/toolbar" app:layout_scrollFlags="scroll|enterAlways" /> </android.support.design.widget.AppBarLayout> <FrameLayout android:id="@+id/content_frame" android:layout_below="@id/toolbar_layout" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> <android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="400dp" android:layout_height="match_parent" android:layout_gravity="left" app:headerLayout="@layout/nav_header" app:menu="@menu/nav_menu" /> </android.support.v4.widget.DrawerLayout>
コード(MainActivity.cs)
using Android.App; using Android.Content.PM; using Android.Content.Res; using Android.OS; using Android.Support.V4.Widget; using Android.Views; using Android.Widget; using App4.Fragments; using Android.Support.V7.App; using Android.Support.V4.View; using Android.Support.Design.Widget; namespace App4.Activities { [Activity(Label = "Home", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, Icon = "@drawable/Icon")] public class MainActivity : BaseActivity { DrawerLayout drawerLayout; NavigationView navigationView; protected override int LayoutResource { get { return Resource.Layout.main; } } protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); drawerLayout = this.FindViewById<DrawerLayout>(Resource.Id.drawer_layout); //Set hamburger items menu SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu); //setup navigation view navigationView = FindViewById<NavigationView>(Resource.Id.nav_view); //handle navigation navigationView.NavigationItemSelected += (sender, e) => { e.MenuItem.SetChecked(true); switch (e.MenuItem.ItemId) { case Resource.Id.nav_home_1: ListItemClicked(0); break; case Resource.Id.nav_home_2: ListItemClicked(1); break; } Snackbar.Make(drawerLayout, "You selected: " + e.MenuItem.TitleFormatted, Snackbar.LengthLong) .Show(); drawerLayout.CloseDrawers(); }; //if first time you will want to go ahead and click first item. if (savedInstanceState == null) { ListItemClicked(0); } } int oldPosition = -1; private void ListItemClicked(int position) { //this way we don't load twice, but you might want to modify this a bit. if (position == oldPosition) return; oldPosition = position; Android.Support.V4.App.Fragment fragment = null; switch (position) { case 0: fragment = Fragment1.NewInstance(); break; case 1: fragment = Fragment2.NewInstance(); break; } SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.content_frame, fragment) .Commit(); } public override bool OnOptionsItemSelected(IMenuItem item) { switch (item.ItemId) { case Android.Resource.Id.Home: drawerLayout.OpenDrawer(Android.Support.V4.View.GravityCompat.Start); return true; } return base.OnOptionsItemSelected(item); } } }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。