一个接一个地动画图像

时间:2012-10-03 06:17:08

标签: android animation viewflipper

我试图动态地将imageViews添加到表格布局上,我的要求是imageView中的图像必须一个接一个地动画,并且所有图像都应该保留在视图本身上。

但问题是图像不是一个接一个地动画,而是整个图像集一次淡入。但是我希望这些图像能够一个接一个地淡入淡出,而不是发生。

请帮帮我。

提前致谢

5 个答案:

答案 0 :(得分:2)

通过使用AsyncTask逐个添加图像到视图中。

@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;
}

答案 1 :(得分:1)

以下是我的建议,你可以从android ViewFlipper开始,让动画像图像淡入淡出。在ViewFlipper上搜索可以帮助你入门的例子。

答案 2 :(得分:1)

确定有解决方案,您可以根据动画要求创建多个图像帧,然后您可以将这些图像添加到可绘制文件夹中。然后使用这样的动画。 <animation-list
xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/imvControl" android:oneshot="false"> <item android:drawable="@drawable/image1" android:duration="100" /> <item android:drawable="@drawable/image1" android:duration="100" /> <item android:drawable="@drawable/image1" android:duration="100" /> </animation-list>

有关详情,请浏览this link。祝你好运!

答案 3 :(得分:0)

定义一个扩展动画的类,并提到你可以使用ViewFlipper交换图像,因为Herry说

答案 4 :(得分:0)

 t1.schedule(new TimerTask() {
                int i =4;
                @Override
                public void run() {
                    // TODO Auto-generated method stub

                    if(i<0){
                        i=4;
                    }
                    else
                    {
                    Message m=new Message();
                    m.arg1=i;
                    imgHandler.sendMessage(m);
                    i--;
                    }
                }
            }, 0,1000);
 Handler imgHandler=new Handler(){

        public void handleMessage(Message msg) {



            imgLogo.setImageDrawable(images[msg.arg1]);             

        };

我使用此代码依次显示图像

相关问题