我正在尝试将DragnDrop列表视图从这里https://github.com/commonsguy/cwac-touchlist转换为C#和Mono。
这个自定义视图的一部分需要使用一些自定义属性,这些属性在文件Resources/value/atts.xml中声明如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="TouchListView">
<attr name="normal_height" format="dimension" />
<attr name="expanded_height" format="dimension" />
<attr name="grabber" format="reference" />
<attr name="dragndrop_background" format="color" />
<attr name="remove_mode">
<enum name="none" value="-1" />
<enum name="fling" value="0" />
<enum name="slide" value="1" />
<enum name="slideRight" value="1" />
<enum name="slideLeft" value="2" />
</attr>
</declare-styleable>
</resources>然后,我尝试在布局文件中使用它们,如下所示:
<app.monodroid.TouchListView xmlns:tlv="http://schemas.android.com/apk/res/app.monodroid"
android:id="@+id/lstExercises"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/lExerciseActions"
android:drawSelectorOnTop="false"
tlv:normal_height="64dip"
tlv:grabber="@+id/icon"
tlv:remove_mode="slideRight"
/>但是,当我试图构建我的项目时,我会收到以下错误消息:
/Library/Frameworks/Mono.framework/External/xbuild/Novell/Novell.MonoDroid.Common.targets:错误:与代码一起退出的工具: 1.输出: /Users/path_to_project/App.MonoDroid/obj/Debug/res/layout/add_session.axml:1:错误:在包'com.app.monodroid‘/Users/path_to_project/App.MonoDroid/obj/Debug/res/layout/add_session.axml:1:中找不到属性'normal_height’的资源标识符错误:在包‘/Users/path_to_project/App.MonoDroid/obj/Debug/res/layout/add_session.axml:1:’com.app.monodroid中找不到属性'grabber‘的资源标识符:没有为包'com.app.monodroid’中的属性'remove_mode‘找到资源标识符(App.MonoDroid)
我的项目名为App.MonoDroid。
如何在布局文件中使用这些属性?
发布于 2012-01-21 14:43:10
如果您为应用程序声明了包名,这些错误就会消失。在项目属性中,转到Android选项卡,您将看到包名的文本字段:

发布于 2012-09-26 20:50:23
..。然后确保将此包名称用于程序集和命名空间:

并在xml文件中使用它:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/**app.monodroid**"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<**app.monodroid**.FICalendarView
android:id="@+id/FICalendar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
custom:dayStyle="1">
</**app.monodroid**.FICalendarView>
<Button
android:id="@+id/MyButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Hello"/>
</LinearLayout>其中FICaldendarView是一个自定义视图,定义为:
namespace app.monodroid
{
public class FICalendarView : View
{
//private FICalenderView() {}
public FICalendarView(Context context)
: base(context)
{
}
public FICalendarView(Context context, Android.Util.IAttributeSet attribute)
: base(context, attribute)
{
Android.Content.Res.TypedArray a = context.Theme.ObtainStyledAttributes(attribute, Resource.Styleable.FICalendarView, 0, 0);
//Android.Util.TypedValue typedValue = null;
int dayStyle = a.GetInteger(Resource.Styleable.FICalendarView_dayStyle,0);
}
public FICalendarView(Context context, Android.Util.IAttributeSet attribute, int x)
: base(context, attribute,x)
{
}
}
}https://stackoverflow.com/questions/8952470
复制相似问题