Xamarin Android FrameLayout在预期关闭应用程序的背面显示空白/空片段(Xamarin Android FrameLayout displays blank/empty fra

编程入门 行业动态 更新时间:2024-10-27 01:21:00
Xamarin Android FrameLayout在预期关闭应用程序的背面显示空白/空片段(Xamarin Android FrameLayout displays blank/empty fragment on back where expected to close the app)

我正在实现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!

更多推荐

本文发布于:2023-07-30 01:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1321429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:背面   应用程序   片段   空白   FrameLayout

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!