【发布时间】:2018-09-29 10:44:32
【问题描述】:
使用 Visual Studio 开发 Xamarin 跨平台 APP。我已将特定的 Android 代码添加到 Android 特定版本中。尝试编译时出现 CS0117 错误。我在 Resources/layout 文件夹中有一个“V2T.axml”文件。 CS代码中出现错误的行是:
SetContentView(Resource.Layout.V2T);
知道有什么问题吗?
另外还有 2 个 CS0117 错误,原因是“Resource.Id”不包含定义错误 - 但我已经定义了这两个资源。
有什么想法吗?
CS:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// set the isRecording flag to false (not recording)
isRecording = false;
// Set our view to: V2T.axml
SetContentView(Resource.Layout.V2T);
// get the resources from the layout
recButton = FindViewById<Button>(Resource.Id.btnRecord);
textBox = FindViewById<TextView>(Resource.Id.textYourText);
V2T.axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="3">
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout1"
android:layout_weight="1"
android:gravity="center">
<Button
android:text="Start Recording"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnRecord" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2"
android:layout_weight="1">
<TextView
android:text="Your text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:layout_marginLeft="5dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/textYourText"
android:textColor="#ffedf01d"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout3"
android:layout_weight="1" />
</LinearLayout>
【问题讨论】:
-
考虑发布更多代码
-
这里是代码 sn-p: CS: protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // 将 isRecording 标志设置为 false(不录制) isRecording = false; // 将我们的视图设置为:V2T.axml SetContentView(Resource.Layout.V2T); // 从布局中获取资源 recButton = FindViewById
-
SetContentView(Resource.Layout.V2T);这一行有什么问题? -
不确定 - 我在一个独立的应用程序中使用了这个确切的代码并且它有效。我错过了什么?
-
请发布错误
标签: c# setcontentview