【发布时间】:2018-03-15 09:53:35
【问题描述】:
我在开发 Android 应用程序时遇到了 Visual Studio 2015 的问题。
由于某种原因,我无法在 MyActivity 中设置主视图
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Id.Main);
}
构建时返回错误“'Resource.Id'不包含'Main'的定义”,尽管该视图称为“Main.axml” 我以前确实遇到过这个问题,但可以通过保存视图来解决这个问题,这总是有帮助的。
我不确定,但它似乎与最近的 Xamarin 更新有关。
我尝试了几件事:清理解决方案,重建(以错误结束),关闭 VS 并重新打开,重新启动计算机。 我还创建了一个新项目,但这也无济于事。
下面是我的(简单)Main.axml 文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="read" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
【问题讨论】:
-
尝试删除bin和obj,然后重启你的VS。如果还是不行,请使用VS 2017。
标签: c# android visual-studio android-layout xamarin