动态创建许多对象后动画变得迟钝

时间:2019-02-09 20:36:40

标签: java android

我有以下代码,在创建约400个ImageView实例(通过调用updateUI(NewImage)〜400次)之后,新创建的ImageView动画会比较滞后,经过的时间越长,他们变得迟钝。我认为在完成ImageView动画之后,我必须销毁它们,以免出现延迟。有什么主意吗?

public  void updateUI(final Bitmap bitmap)
   {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            final ImageView tmp = new ImageView(getApplicationContext());
            tmp.setImageBitmap(bitmap);
            tmp.setY(AT_THE_BOTTON_OF_ACTIVITY);
            rv.addView(tmp); add the ImageView to the Relalayout
           tmp.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View view) {
                    //disappear the imageView
                    ImageView t=imgs.get(id);
                    ObjectAnimator opacity = ObjectAnimator.ofFloat(tmp(The ImageView), "alpha", 0.0f);
                    opacity.setDuration(200);
                    opacity.start();

               }
           });

            ObjectAnimator anim2 = ObjectAnimator.ofFloat(tmp, "y", 0);
            anim2.setDuration(5000);
            anim2.setInterpolator(new LinearInterpolator());
            anim2.start();
        }
    });
}

0 个答案:

没有答案