ObjectAnimator代理以动画TOPMARGIN无法找到设置/吸气 [英] ObjectAnimator Proxy to Animate TopMargin can't find setting/getter
问题描述
我们正在尝试使用objectanimator代理动画的安卓(Xamarin)的TOPMARGIN属性。
We are trying to use an objectanimator proxy to animate the TopMargin property in Android (Xamarin).
不过,我们得到这个错误:
However, we get this error:
[PropertyValuesHolder]找不到二传手/ getter方法属性 值类型为浮动TOPMARGIN
[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.
我们的code。在活动启动动画:
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.
感谢。
推荐答案
您需要将[出口]属性添加到您的getTopMargin和setTopMargin方法。例如,
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();
}
[导出]属性还要求你添加一个引用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
这篇关于ObjectAnimator代理以动画TOPMARGIN无法找到设置/吸气的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!