我正在实现Fragments和hamburger,但是当我点击后退按钮时,我注意到content_frame (由片段填充)在最后一次“后退”按下时总是为空(我希望关闭应用程序而不是显示空内容)。
下面是我的FirstView.axml
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:local="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer_layout" android:layout_height="match_parent" android:layout_width="match_parent"> <android.support.design.widget.CoordinatorLayout android:id="@+id/main_frame" android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerInParent="true" /> </android.support.design.widget.CoordinatorLayout> <FrameLayout android:id="@+id/navigation_frame" android:layout_height="match_parent" android:layout_width="wrap_content" android:layout_gravity="left|start" />这是我活动中的OnBackPressed
public override void OnBackPressed() { if (DrawerLayout != null && DrawerLayout.IsDrawerOpen(GravityCompat.Start)) DrawerLayout.CloseDrawers(); else base.OnBackPressed(); }要在片段之间导航,我使用MenuFragment导航功能
private async Task Navigate(int itemId) { ((FirstView)Activity).DrawerLayout.CloseDrawers(); // add a small delay to prevent any UI issues await Task.Delay(TimeSpan.FromMilliseconds(250)); switch (itemId) { case Resource.Id.nav_input: ViewModel.ShowInputCommand.Execute(); break; case Resource.Id.nav_registercc: ViewModel.ShowRegisterCCCommand.Execute(); break; case Resource.Id.nav_creditcard: ViewModel.ShowCreditCardCommand.Execute(); break; case Resource.Id.nav_transaction: ViewModel.ShowTransactionCommand.Execute(); break; } }基本上,我面临的问题是在content_frame显示初始片段之后关闭应用程序,它显示空/空片段( navigation_frame仍在工作)。 正如您所看到的,我正在关注MvvmCross教程中的所有内容。
任何帮助,将不胜感激。
I am implementing Fragments and hamburger, however when I click the back button I noticed the content_frame (which is filled by fragment) is always empty on the last 'back' pressed (where I expected to close the app instead of showing empty content).
Below is my FirstView.axml
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:local="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer_layout" android:layout_height="match_parent" android:layout_width="match_parent"> <android.support.design.widget.CoordinatorLayout android:id="@+id/main_frame" android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerInParent="true" /> </android.support.design.widget.CoordinatorLayout> <FrameLayout android:id="@+id/navigation_frame" android:layout_height="match_parent" android:layout_width="wrap_content" android:layout_gravity="left|start" />Here is the OnBackPressed from my activity
public override void OnBackPressed() { if (DrawerLayout != null && DrawerLayout.IsDrawerOpen(GravityCompat.Start)) DrawerLayout.CloseDrawers(); else base.OnBackPressed(); }To navigate between fragment, I use navigate function from my MenuFragment
private async Task Navigate(int itemId) { ((FirstView)Activity).DrawerLayout.CloseDrawers(); // add a small delay to prevent any UI issues await Task.Delay(TimeSpan.FromMilliseconds(250)); switch (itemId) { case Resource.Id.nav_input: ViewModel.ShowInputCommand.Execute(); break; case Resource.Id.nav_registercc: ViewModel.ShowRegisterCCCommand.Execute(); break; case Resource.Id.nav_creditcard: ViewModel.ShowCreditCardCommand.Execute(); break; case Resource.Id.nav_transaction: ViewModel.ShowTransactionCommand.Execute(); break; } }Basically, the issue that I am facing is instead of closing the app after content_frame showing the initial fragment, it displays empty/blank fragment (navigation_frame still working). And as you can see, I am following everything from this MvvmCross tutorial.
Any help would be appreciated.
最满意答案
我只是在我的初始片段中认识到标题应该是[MvxFragment(typeof(FirstViewModel), Resource.Id.content_frame)]而不是[MvxFragment(typeof(FirstViewModel), Resource.Id.content_frame, true)] 。 现在它按预期工作得很好!
I just realize in my initial fragment the header should be [MvxFragment(typeof(FirstViewModel), Resource.Id.content_frame)] instead of [MvxFragment(typeof(FirstViewModel), Resource.Id.content_frame, true)]. It is now working great as expected!
更多推荐
发布评论