show multiple images animation
I want to show a background image and multiple images moving down just like "snowfall" scene so how can I do that?Background image should not move, only small images over it should be falling down.How can i do this????
Update--> I have displayed images on screen but they all are coming at the same time but I want to show images coming at different time how can I do this?hey please suggest some way.is this the right way or if not please suggest me the correct way ....
Here is my code:
public class AnimationActivity extend开发者_运维知识库s Activity implements AnimationListener
{
/** Called when the activity is first created. */
LinearLayout layout;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Animation movement;
layout = (LinearLayout) findViewById(R.id.linearLayout_ani);
movement = AnimationUtils.loadAnimation(this,R.layout.abc);
movement.reset();
movement.setFillAfter(true);
movement.setAnimationListener(this);
movement.setRepeatCount(1);
movement.setRepeatMode(7);
layout.startAnimation(movement);
}
@Override
public void onAnimationEnd(Animation movement)
{
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation arg0)
{
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation arg0)
{
}
}
Here is the animation layout file:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%"
android:toXDelta="50%"
android:fromYDelta="0%"
android:toYDelta="95%"
android:duration="10000"
android:zAdjustment="normal" />
main .xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/wall">
<LinearLayout android:id="@+id/linearLayout_ani"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<ImageView android:id="@+id/snowimg1"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:visibility="visible"
android:background="@drawable/snow1"
></ImageView>
<ImageView android:id="@+id/snowimg2"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:visibility="visible"
android:background="@drawable/snow1"
></ImageView>
<ImageView android:id="@+id/snowimg3"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:visibility="visible"
android:background="@drawable/snow1"
></ImageView>
<ImageView android:id="@+id/snowimg4"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:visibility="visible"
android:background="@drawable/snow1"
></ImageView>
<ImageView android:id="@+id/snowimg5"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:visibility="visible"
android:background="@drawable/snow1"
></ImageView>
<ImageView android:id="@+id/snowimg6"
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:visibility="visible"
android:background="@drawable/snow1"
>
</ImageView>
</LinearLayout>
</LinearLayout>
You could add the animator for all the images like this:
private final int REPEAT_COUNT = 1;
private final int REPEAT_MODE = 7;
private void startAnimations() {
// Using the ImageView not the layout.
ImageView snowImg1 = (ImageView) findViewById(R.id.snowimg1);
ImageView snowImg2 = (ImageView) findViewById(R.id.snowimg2);
ImageView snowImg3 = (ImageView) findViewById(R.id.snowimg3);
ImageView snowImg4 = (ImageView) findViewById(R.id.snowimg4);
ImageView snowImg5 = (ImageView) findViewById(R.id.snowimg5);
ImageView snowImg6 = (ImageView) findViewById(R.id.snowimg6);
ImageView snowArray[] = {snowImg1, snowImg2, snowImg3, snowImg4, snowImg5, snowImg6};
// If it is not the same movement, you will need to create different layouts
Animation snowMov1 = AnimationUtils.loadAnimation(this, R.layout.snowimg1);
Animation snowMov2 = AnimationUtils.loadAnimation(this, R.layout.snowimg2);
Animation snowMov3 = AnimationUtils.loadAnimation(this, R.layout.snowimg3);
Animation snowMov4 = AnimationUtils.loadAnimation(this, R.layout.snowimg4);
Animation snowMov5 = AnimationUtils.loadAnimation(this, R.layout.snowimg5);
Animation snowMov6 = AnimationUtils.loadAnimation(this, R.layout.snowimg6);
Animation movArray[] = {snowMov1, snowMov2, snowMov3, snowMov4, snowMov5, snowMov6};
// Start the movement animation.
startMovement(snowArray, movArray);
}
private void startMovement(ImageView imgArray[], Animation movArray[]) {
// Same length so there is no problem...
int length = imgArray.length;
for(int i = 0; i < length; i++) {
movArray[i].reset();
movArray[i].setFillAfter(true);
movArray[i].setAnimationListener(this);
movArray[i].setRepeatCount(REPEAT_COUNT);
movArray[i].setRepeatMode(REPEAT_MODE);
// Start the animation
imgArray[i].startAnimation(movArray[i]);
}
}
You will need to make random movements in the animation file, this was not tested so Im not sure if it works... I hope it helps at least I tried.
EDIT:
Don't be impatient, help will come soon if my approach does not work!, you just need to wait man...
精彩评论