Search code examples
androidanimationviewflipper

Animating images one after the other


Am trying to add imageViews onto a table layout dynamically and my requirement is that the images in the imageView have to be animated one after the other and all the image should retain on the view itself.

But the problem is the images are not getting animated one after the other rather the whole set of image fades in at once. But I want the images to fade-in one after the other which is not happening.

Please help me out.

Thanks in advance


Solution

  • By using AsyncTask add images to the view one by one .

    @Override
    protected Void doInBackground(Void... params) {
    
        runOnUiThread(new Runnable() {
            public void run() {             
                int a =0;
                for (Integer row = 0; row < rows; row++) {
    
                    tableRow = new TableRow(getApplicationContext());
                    for (Integer col = 0; col < img; col++) {
    
                        image = new ImageView(getApplicationContext());
                        android.view.animation.Animation anim = animate(a);
                        /*android.view.animation.Animation anim = AnimationUtils
                                    .loadAnimation(getApplicationContext(), R.anim.fadein);*/
                        image.startAnimation(anim);
                        image.setPadding(20, 20, 20, 20);
    
                            image.setImageResource(R.drawable.images);
                        tableRow.addView(image);
                        a++;
                    }
                    tableLayout.addView(tableRow);
                }
                VSC.addView(tableLayout);
                HSC.addView(VSC);
                setContentView(HSC);
            }
        });
    
        return null;
    }