gpt4 book ai didi

android - 如何在 MvvmCross 版本中制作 DrawerMenu?五.4.2

转载 作者:行者123 更新时间:2023-11-30 00:16:27 28 4
gpt4 key购买 nike

我正在使用来自 MvvmCross 存储库的StarWarsEaxmple,但我无法让它工作。 MvvmCross 的输出,我认为问题出在不同版本的 MvvmCross 或 Presenter 中。 在样本中版本是 5.1.1,在我的项目中是 5.4.2。 并且表现出奇怪的行为。

当我不涉及 MvvmCross NavigationService 时,我可以看到空抽屉。但是,当我依次导航到两个 ViewModel 时(如示例中所示),我只能看到没有抽屉的菜单页面,甚至不会调用其他页面框架。

Reference to MvvmCross Sample

主要 Activity

[Activity(Icon = "@drawable/icon", 
Theme = "@style/AppTheme", LaunchMode = LaunchMode.SingleTop,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : MvxCachingFragmentCompatActivity<MainViewModel>
{
public DrawerLayout DrawerLayout;
//This method is invoked
protected override void OnCreate(Bundle bundle)
{ base.OnCreate(bundle);
SetContentView(Resource.Layout.activity_main);

DrawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawerLayout);

ViewModel.ShowDefaultMenuItem();
}
....

菜单 fragment

[MvxFragment(typeof(MainViewModel), Resource.Id.navigationFrame)]
[Register("VacationManager.Droid.Activities.MenuFragment")]
public class MenuFragment : MvxFragment<MenuViewModel>, NavigationView.IOnNavigationItemSelectedListener
{
private NavigationView _navigationView;
private IMenuItem _previousMenuItem;

//This method is invoked too
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{

base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.menu_view, null);

_navigationView = view.FindViewById<NavigationView>(Resource.Id.navigation_view);
_navigationView.SetNavigationItemSelectedListener(this);

return view;
}
}

页面主要部分

[MvxFragment(typeof(MainViewModel), Resource.Id.bodyFrame, false)]
[Register("VacationManager.Droid.Activities.VacationRequestListFragment")]
public class VacationRequestListFragment : BaseFragment<VacationRequestListViewModel> // You can find BaseFragment in sample
{
protected override int FragmentId => Resource.Layout.fragment_list;
//It is never invoked
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
return this.BindingInflate(Resource.Layout.fragment_list, container, false);
}
}

主页布局

<?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/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/warning">

<!-- Center Side -->


<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainFrame">

<include layout="@layout/toolbar" />
<FrameLayout
android:id="@+id/bodyFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"/>

<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@drawable/bullseye"
local:layout_anchor="@id/bodyFrame"
local:layout_anchorGravity="bottom|right|end" />

</android.support.design.widget.CoordinatorLayout>

<!-- Left Side -->
<FrameLayout
android:id="@+id/navigationFrame"
android:layout_height="match_parent"
android:layout_width="240dp"
android:layout_gravity="left|start"
android:clickable="true" />

</android.support.v4.widget.DrawerLayout>

主页布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:theme="@style/ThemeToolbarNavigationView"
android:background="@color/colorPrimary"
local:itemTextColor="@color/light_gray"
local:itemIconTint="@color/light_gray"
local:headerLayout="@layout/navigation_header"
local:menu="@menu/navigation_drawer" />

主视图模型

public void ShowDefaultMenuItem()
{
NavigationService.Navigate<VacationRequestListViewModel>();
NavigationService.Navigate<MenuViewModel>();
}

似乎我遗漏了一些小细节...如有任何帮助,我们将不胜感激。

最佳答案

问题首先出在 Activity 属性的命名空间中。它们应该是 MvvmCross.Droid.Views.Fragments 。我们还需要使用 MvxFragmentPresentationAttribute 而不是 MvxFragmentAttribute。然后就可以了。

关于android - 如何在 MvvmCross 版本中制作 DrawerMenu?五.4.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47178949/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com