xamarin - Xamarin + MvvmCross 6.0 无法实现标签导航
问题描述
我正在使用 MvvmCross 构建一个简单的 Xamarin 应用程序,但目前无法实现选项卡导航。我收到 Mvx 异常:未找到 viewpager 或 tablayout
这是我的主要活动:
[MvxActivityPresentation]
[Activity(Theme = "@style/MainTheme",ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation |
Android.Content.PM.ConfigChanges.ScreenSize)]
public class TabsRootView : MvxAppCompatActivity<TabsRootViewModel>
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.tabs_root_view);
if (bundle == null)
{
ViewModel.ShowInitialViewModelsCommand.Execute();
}
}
}
这是我的标签根视图布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
local:layout_scrollFlags="scroll|enterAlways">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
local:tabGravity="center"
local:tabMode="scrollable" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
local:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
这应该是我的标签内容片段之一(另一个看起来几乎相同):
[MvxTabLayoutPresentation(TabLayoutResourceId = Resource.Id.tabs, ViewPagerResourceId = Resource.Id.viewpager, Title = "Bacheca", ActivityHostViewModelType = typeof(TabsRootViewModel))]
[Register(nameof(PostsView))]
public class PostsView : MvxFragment<PostsViewModel>
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.posts_view, null);
// RecyclerView
var recyclerView = view.FindViewById<MvxRecyclerView>(Resource.Id.recycler_view);
recyclerView.SetLayoutManager(new LinearLayoutManager(Activity));
recyclerView.HasFixedSize = false;
// Swipe touch helper
var callback = new SwipeItemTouchHelperCallback(ViewModel);
var touchHelper = new ItemTouchHelper(callback);
touchHelper.AttachToRecyclerView(recyclerView);
return view;
}
}
解决方案
推荐阅读
- image - 在 Colab 中,为什么图像在相同的代码单元中时不显示在执行的文件中?
- javascript - 如何改进我在 JavaScript 中的验证?
- laravel - 使用 laravel 护照令牌保护网络路由
- c++ - 一次性使用类成员变量的内存使用
- node.js - ReactJS 不使用 socket.io 与 NodeJS API 连接
- php - 在远程 API 回复后关闭和重新打开 mysql 连接
- mysql - 迄今为止的 MySQL 字符串将所有行都带入同一年份
- r - 替换因子中的未知值
- r - 以 papaja 为例,当 github 被阻塞时如何安装 R 包
- infinite-scroll - svelte-tiny-virtual-list + svelte-infinite-loading 在页面加载时崩溃