【发布时间】:2016-01-05 22:30:12
【问题描述】:
我在 Xamarin Android 应用程序中将文本视图作为标题添加到列表视图。 按照 ericosg 对this SO question 的回答中的说明,我将 textview 放在单独的 axml 文件中,然后尝试将其作为标题添加到我的列表视图中。
运行应用程序在 Activity 尝试使 textview 膨胀的那一行出现以下错误:
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Android.Content.Res.Resources+NotFoundException: Exception of type 'Android.Content.Res.Resources+NotFoundException' was thrown.
.
.
.
[MonoDroid] --- End of managed exception stack trace ---
[MonoDroid] android.content.res.Resources$NotFoundException: Resource ID #0x7f050006 type #0x12 is not valid
[MonoDroid] at android.content.res.Resources.loadXmlResourceParser(Resources.java:2250)
etc.
这是我的代码:
在 Activity .cs 文件中:
myListView = FindViewById<ListView>(MyApp.Resource.Id.MyList);
Android.Views.View myHeader =
this.LayoutInflater.Inflate(MyApp.Resource.Id.QuestionText, myListView);
myListView.AddHeaderView(myHeader);
ListView 定义:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/MyList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</RelativeLayout>
标题定义:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/QuestionText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableTop="@+id/MyImage" />
【问题讨论】: