在 ObjectAnimator 中指定 propertyName 时找不到使用 JNI 错误的本机方法

Can't find native method using JNI error when specifying propertyName in ObjectAnimator

我正在尝试制作滑动片段,如以下代码所示:https://github.com/lucamtudor/Sliding-Fragments

但是,当移植到 Xamarin 时,出现错误:

01-26 18:07:10.943 D/PropertyValuesHolder(17296): Can't find native method using JNI, use reflectionjava.lang.NoSuchMethodError: no method with name='setYFraction' signature='(F)V' in class Ltestappandroid/FractionalLinearLayout;
01-26 18:07:10.943 E/PropertyValuesHolder(17296): Couldn't find setter/getter for property yFraction with value type float

自定义动画如下所示:

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:valueFrom="0"
    android:valueTo="@dimen/slide_up_down_fraction"
    android:propertyName="yFraction"
    android:valueType="floatType"
    android:duration="@integer/slide_up_down_duration">
</objectAnimator>

在我的 FractionalLinearLayout 中我有:

public float getYFraction()
{
    return mYFraction;
}

public void setYFraction(float yFraction)
{
    mYFraction = yFraction;
    SetY((mScreenHeight > 0) ? (mScreenHeight - yFraction * mScreenHeight) : 0);
}

当然,我还添加了一个首字母大写的副本,以及首字母大写和非大写的 C# 属性,但它不起作用(同样的错误)。

尝试使用 Xamarin 引用 xml 中的方法时是否有任何问题? 完整代码可在此处获得:http://home.harteex.com/TestAppAndroid.zip

最后,我也看到了这个,不知道它是否相关:

01-26 18:07:10.853 I/dalvikvm(17296): Could not find method android.widget.LinearLayout.<init>, referenced from method testappandroid.FractionalLinearLayout.<init>
01-26 18:07:10.853 W/dalvikvm(17296): VFY: unable to resolve direct method 233: Landroid/widget/LinearLayout;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;II)V
01-26 18:07:10.853 D/dalvikvm(17296): VFY: replacing opcode 0x70 at 0x0000

您需要向 getter 和 setter 添加 [Export] 属性。

[Export]
public float getYFraction()
{
    return mYFraction;
}

[Export]
public void setYFraction(float yFraction)
{
    mYFraction = yFraction;
    SetY((mScreenHeight > 0) ? (mScreenHeight - yFraction * mScreenHeight) : 0);
}

参见:ObjectAnimator Proxy to Animate TopMargin can't find setting/getter