【发布时间】:2018-03-05 02:01:54
【问题描述】:
首先,我的最终目标是为安卓应用动态创建一个汉堡菜单。汉堡菜单需要有主菜单项,每个主菜单项都有一组子菜单项。
然而,在我到达那里之前,我只是想创建一个简单的菜单项列表视图显示。每个菜单项都包含一个字符串(标签)和字符串列表(标签)/guid 组合。
我的 ViewModel 包含以下内容:
public MvxObservableCollection<MenuItem> MenuItems { get; private set; }
public class MenuItem
{
public MenuItem(string title)
{
Title = title;
}
public string Title { get; private set; }
}
我的 View axml 定义如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
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"
local:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<Mvx.MvxListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxItemTemplate="@layout/listitem_mainmenu"
local:MvxBind="ItemsSource MenuItems" />
</RelativeLayout>
listitem_mainmenu.axml 定义如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
local:MvxBind="Text Title; Click ShowDashboard" />
</LinearLayout>
我已经调试并验证了我的 MenuItems 集合确实包含 8 个项目。但是,当显示出现时,仿真设备中不会显示任何内容。
任何建议: 1)让这个项目列表显示出来,和 2)最终将其转换为汉堡菜单 将不胜感激。
【问题讨论】:
-
谢谢,样本看起来很深。我看到它正在使用 MvvmCross 4.x 并引用了许多其他技术。 v5 更侧重于视图和视图模型以保持一致性,而不是活动(特定于 Android)。如果有一个 MvvmCross 5.x 版本真正涵盖并解释了 Android 和 iOS 的功能和用法,以更易于理解的格式会有所帮助。当您在所见内容的背景下查看代码时,这很棒。
-
嗨,在您的
listitem_mainmenu.axml中,将LinearLayout的高度更改为wrap_content,否则每个项目将填满整个屏幕。尝试为您设置颜色TextView。并为你设置不同的背景TextView和`listitem_mainmenu。以上只是为了测试一些东西。 Here 是官方示例,我想你显示下载并运行。 -
“官方样本”不起作用。我使用的是 MvvmCross 5.2.1,Cirrious 是早期版本的一部分。
标签: c# android xamarin mvvmcross