问题描述
这是我的第一个 Xamarin 应用程序.我在 Visual Studio 中设置了环境,并且有一个可以在 Android 模拟器中运行的模板项目.
This is my first Xamarin app. I have my environment set up in Visual Studio, and have a template project which I can run in the Android emulator.
将几个控件拖放到设计器界面后,我发现当我在模拟器中运行应用程序时,我添加的两个控件(一个按钮和一个开关)都没有显示在模拟器中.
Having dragged and dropped a couple of controls on to the designer surface, I find that when I run the application in the emulator, neither of the two controls that I have added (a button and a switch) display in the emulator.
我试过了:
- 清洁溶液
- 重建解决方案
- 手动删除 bin 和目标文件
- 在项目 Android 选项中取消选中使用快速部署"
- 从模拟器卸载
但每次都得到相同的结果.
But with the same result each time.
[删除项目文件]
我错过了什么吗?
推荐答案
刚刚下载并运行了您的代码.取消注释 SetContentView (Resource.Layout.Main);
它对我有用.
Just downloaded your code and ran it. Uncommenting SetContentView (Resource.Layout.Main);
it worked to me.
[Activity(Label = "Tgo.AndroidApp", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
}
}
这里是一个很好的指南从 Xamarin Android 开始.
Here a nice guide to get you started with Xamarin Android.
这篇关于控件显示在设计器中但不在模拟器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!