用于动画 TopMargin 的 ObjectAnimator 代理找不到设置/获取器 [英] ObjectAnimator Proxy to Animate TopMargin can't find setting/getter

查看:24
本文介绍了用于动画 TopMargin 的 ObjectAnimator 代理找不到设置/获取器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试使用 objectanimator 代理为 Android (Xamarin) 中的 TopMargin 属性设置动画.

We are trying to use an objectanimator proxy to animate the TopMargin property in Android (Xamarin).

然而,我们得到这个错误:

However, we get this error:

[PropertyValuesHolder] 找不到属性的 setter/getterTopMargin 值类型为 float

[PropertyValuesHolder] Couldn't find setter/getter for property TopMargin with value type float

注意:我们尝试了TopMargin、topMargin、GetTopMargin、getTopMargin等,认为可能是Java和C#之间大小写转换的问题,但看起来不是这样.

Note: we tried TopMargin, topMargin, GetTopMargin, getTopMargin, etc., thinking that it might be an issue of casing conversion betwen Java and C#, but it doesn't look to be the case.

我们在Activity中启动动画的代码:

Our code in the Activity starting the animation:

translation = new int[] {0, 300};
var anim2 = ObjectAnimator.OfInt( new MarginProxyAnimator(myview), "TopMargin",translation);
anim2.SetDuration(500);
anim2.Start(); 

我们的代理类:

public class MarginProxyAnimator : Java.Lang.Object 
{
///... other code...
    public int getTopMargin() {
    var lp = (ViewGroup.MarginLayoutParams)mView.LayoutParameters;
    return lp.TopMargin;
    }

    public void setTopMargin(int margin) {
    var lp = (ViewGroup.MarginLayoutParams)mView.LayoutParameters;
        lp.SetMargins(lp.LeftMargin, margin, lp.RightMargin, lp.BottomMargin);
    mView.RequestLayout();
    }
}

有什么建议吗?指向使用代理的工作 Xamarin 示例的指针会很有帮助.

Any advise? a pointer to a working Xamarin sample using a proxy would be helpful.

谢谢.

推荐答案

您需要将 [Export] 属性添加到您的 getTopMargin 和 setTopMargin 方法中.E.G.

You need to add the [Export] attribute to your getTopMargin and setTopMargin methods. E.G.

[Export]
public int getTopMargin()
{
  var lp = (ViewGroup.MarginLayoutParams)mView.LayoutParameters;
  return lp.TopMargin;
}

[Export]
public void setTopMargin(int margin)
{
  var lp = (ViewGroup.MarginLayoutParams)mView.LayoutParameters;
  lp.SetMargins(lp.LeftMargin, margin, lp.RightMargin, lp.BottomMargin);
  mView.RequestLayout();
}

[Export] 属性还要求您添加对 Mono.Android.Export 程序集的引用.

The [Export] attribute also requires that you add a reference to the Mono.Android.Export assembly.

文档:

http://androidapi.xamarin.com/?link=T%3aJava.Interop.ExportAttribute

这篇关于用于动画 TopMargin 的 ObjectAnimator 代理找不到设置/获取器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆