Reputation: 308
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
Upvotes: 1
Views: 965
Reputation: 22493
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;
}
Upvotes: 2
Reputation: 1506
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]);
};
I used this code to show images sequentially one after the other
Upvotes: 0
Reputation: 3412
Define a class which extends Animation and mention you can make swapping the images using ViewFlipper as Herry said
Upvotes: 0
Reputation: 831
Yes sure there is solution you can create number of image-frames as per your animation requirements and you can then club those images in drawable folder.Then use animation like this.
<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>
For more info go through this link.
Good Luck!
Upvotes: 1
Reputation: 7087
Here are my suggestion for you that you can start with android ViewFlipper
for making Animation like images to fade in and out .Search on ViewFlipper Example that will help you to get started.
Upvotes: 1