好的,所以我以编程方式为我的布局添加视图,然后为它们设置动画,视图似乎正确添加但是当我开始动画时,它似乎无法在这里工作是代码:
Random random = new Random();
final ImageView imageView = new ImageView(getApplicationContext());
final ViewGroup vg = (ViewGroup) animationLayout;
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//params.topMargin = screenHeight;
params.leftMargin = random.nextInt(screenWidth);
vg.addView(imageView,params);
imageView.setImageResource(R.drawable.musical);
imageView.setColorFilter(getResources().getColor(R.color.colorPrimary));
float randomSize = random.nextFloat() * (1.5f - 0.5f) + 0.5f;
imageView.setScaleX(randomSize);
imageView.setScaleY(randomSize);
ObjectAnimator animator = ObjectAnimator.ofInt(imageView, "translationY",0, -screenWidth);
animator.setDuration(15000);
animator.setInterpolator(new LinearInterpolator());
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
Log.e("removed", "true");
vg.removeView(imageView);
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
animator.start();
什么可能导致动画不起作用?动画结束后视图会被删除,所以我不明白
答案 0 :(得分:0)
确定答案看起来像我使用ObjectAnimator.ofInt()
而不是ObjectAnimator.ofFloat()