Xamarin.android MonoDroid如何在布局axml文件中使用自定义属性?

Xamarin.android MonoDroid如何在布局axml文件中使用自定义属性?,xamarin.android,Xamarin.android,我正在尝试将DragndropListView从这里转换为Android的C#with Mono 此自定义视图的一部分要求使用一些自定义属性,这些属性在文件Resources/values/attrs.xml中声明为: <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="TouchListView"> <attr name="normal_heig

我正在尝试将DragndropListView从这里转换为Android的C#with Mono

此自定义视图的一部分要求使用一些自定义属性,这些属性在文件Resources/values/attrs.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”中找不到属性“normal_height”的资源标识符 /Users/path_to_project/App.MonoDroid/obj/Debug/res/layout/add_session.axml:1:错误:在包“com.App.MonoDroid”中找不到属性“grabber”的资源标识符 /Users/path_to_project/App.MonoDroid/obj/Debug/res/layout/add_session.axml:1:错误:在包“com.App.MonoDroid”中找不到属性“remove_mode”的资源标识符 (附单机器人)

我的项目名为App.MonoDroid


如何在布局文件中使用这些属性?

如果为应用程序声明包名,这些错误应该会消失。在项目属性中,转到Android Manifest选项卡,您将看到一个用于包名的文本字段:


。。。然后确保将此包名称用于程序集和命名空间:

并在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>
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)
        {

        }
    }
}