返回信息流ViewGroup.LayoutParams marginLayoutParams1 = new ViewGroup.LayoutParams(10, 20);
ViewGroup.LayoutParams marginLayoutParams2 = new ViewGroup.LayoutParams(400, 800);
ObjectAnimator objectAnimator = ObjectAnimator.ofObject(mImageViewTest, "layoutparams", new MarginEvaluator(), marginLayoutParams1, marginLayoutParams2);
objectAnimator.setDuration(2000);
objectAnimator.addUpdateListener((animation -> {
mImageViewTest.invalidate();
}));
objectAnimator.start();
……
……
……
public class MarginEvaluator implements TypeEvaluator {
public Object evaluate(float fraction, Object startValue, Object endValue) {
float h = ((ViewGroup.LayoutParams) startValue).height + fraction * (((ViewGroup.LayoutParams) endValue).height - ((ViewGroup.LayoutParams) startValue).height);
float w = ((ViewGroup.LayoutParams) startValue).width + fraction * (((ViewGroup.LayoutParams) endValue).width - ((ViewGroup.LayoutParams) startValue).width);
// Log.i("fraction", "" + fraction);
// Log.i("h", "" + (int) h);
// Log.i("w", "" + (int) w);
return new ViewGroup.LayoutParams((int) w, (int) h);
}
}
log有个异常:
W/PropertyValuesHolder﹕ Method setLayoutparams() with type class android.view.ViewGroup$LayoutParams not found on target class class android.widget.ImageView
因为ImageView是放在LinearLayout里面的,所以试着把代码中的ViewGroup.LayoutParams改成LinearLayout.LayoutParams,但还是不行,也有一个类似的异常:
W/PropertyValuesHolder﹕ Method setLayoutparams() with type class android.widget.LinearLayout$LayoutParams not found on target class class android.widget.ImageView
很奇怪,如果直接使用
mImageViewTest.setLayoutParams(new LinearLayout.LayoutParams(400,800));
是可以改变imageview大小的。
然后就不知道是哪出问题了~特来请教一下~
这是一条镜像帖。来源:北邮人论坛 / mobile-terminal-at / #25278同步于 2015/9/25
该镜像源已超过 30 天没有更新,可能在源站已被删除。
MobileTerminalAT机器人发帖
[问题]ObjectAnimator.ofObject如何正确使用?
aName
2015/9/25镜像同步6 回复
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
你自己也说了setLayoutParams,
然后LOG中是setLayoutparams(),
看到区别了吗?
如果改后还是不行,说明该方法不能反射执行,那就得用别的属性去操作该动画效果了
【 在 jerryzcx 的大作中提到: 】
: 你自己也说了setLayoutParams,
: 然后LOG中是setLayoutparams(),
: 看到区别了吗?
: ...................
是说因为P是大写的是吗?那要怎么改成大写的?PropertyName好像大小写都可以的吧
手机上看的捉急 刚起床
【 在 aName (昵称) 的大作中提到: 】
: 额。。。哪没看懂了╭(°A°`)╮
: ☆爱邮☆ 大阅兵喽!
通过『我邮2.0』发布