显示多个图像动画 [英] show multiple images animation

查看:184
本文介绍了显示多个图像动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示一个背景图像和多个图像向下移动,就像雪的场景让我怎么能这样做呢?背景图片不能移动,只有小图片上应该下降down.How我能做到这一点? ???

更新 - > 我已经显示在屏幕上的图像,但他们都来了,在同一时间,但我想显示的图像在不同的时间,我怎么可以这样来了吗?嘿嘿,请提出一些way.is走这条路,或者如果不是,请说明我正确的道路...

下面是我的code:

 公共类AnimationActivity扩展活动实现AnimationListener
{
    / **第一次创建活动时调用。 * /

    的LinearLayout布局;

    @覆盖
    公共无效的onCreate(包savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        动画运动;
        布局=(的LinearLayout)findViewById(R.id.linearLayout_ani);
        运动= AnimationUtils.loadAnimation(这一点,R.layout.abc);
        movement.reset();
        movement.setFillAfter(真正的);
        movement.setAnimationListener(本);
        movement.setRepeatCount(1);
        movement.setRepeatMode(7);

        layout.startAnimation(运动);

    }
    @覆盖
    公共无效onAnimationEnd(动画运动)
    {
        // TODO自动生成方法存根
    }
    @覆盖
    公共无效onAnimationRepeat(动画为arg0)
    {
        // TODO自动生成方法存根

    }
    @覆盖
    公共无效onAnimationStart(动画为arg0)
    {
    }
}
 

下面是动画布局文件:

 < XML版本=1.0编码=UTF-8&GT?;
<翻译的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:fromXDelta =0%
    机器人:toXDelta =50%
    机器人:fromYDelta =0%
    机器人:toYDelta =95%
    机器人:时间=10000
    机器人:zAdjustment =正常/>
 

主要.xml文件

 < XML版本=1.0编码=UTF-8&GT?;

< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
     机器人:ID =@ + ID / LinearLayout中
     机器人:layout_width =FILL_PARENT
     机器人:layout_height =FILL_PARENT
     机器人:方向=垂直
     机器人:背景=@可绘制/墙>

    <的LinearLayout机器人:ID =@ + ID / linearLayout_ani
     机器人:layout_width =FILL_PARENT
     机器人:layout_height =FILL_PARENT
     机器人:方向=横向
     >
    < ImageView的机器人:ID =@ + ID / snowimg1
       机器人:layout_width =WRAP_CONTENT
       机器人:layout_height =WRAP_CONTENT
       机器人:能见度=看见
       机器人:背景=@可绘制/ snow1
       >< / ImageView的>
       < ImageView的机器人:ID =@ + ID / snowimg2
       机器人:layout_width =WRAP_CONTENT
       机器人:layout_height =WRAP_CONTENT
       机器人:能见度=看见
       机器人:背景=@可绘制/ snow1
       >< / ImageView的>
       < ImageView的机器人:ID =@ + ID / snowimg3
       机器人:layout_width =WRAP_CONTENT
       机器人:layout_height =WRAP_CONTENT
       机器人:能见度=看见
       机器人:背景=@可绘制/ snow1
       >< / ImageView的>
       < ImageView的机器人:ID =@ + ID / snowimg4
       机器人:layout_width =WRAP_CONTENT
       机器人:layout_height =WRAP_CONTENT
       机器人:能见度=看见
       机器人:背景=@可绘制/ snow1
       >< / ImageView的>
       < ImageView的机器人:ID =@ + ID / snowimg5
       机器人:layout_width =WRAP_CONTENT
       机器人:layout_height =WRAP_CONTENT
       机器人:能见度=看见
       机器人:背景=@可绘制/ snow1
       >< / ImageView的>
       < ImageView的机器人:ID =@ + ID / snowimg6
       机器人:layout_width =WRAP_CONTENT
       机器人:layout_height =WRAP_CONTENT
       机器人:能见度=看见
       机器人:背景=@可绘制/ snow1
       >
    < / ImageView的>
    < / LinearLayout中>

< / LinearLayout中>
 

解决方案

您可以添加动画像这样所有图像:

 私人最终诠释REPEAT_COUNT = 1;
私人最终诠释REPEAT_MODE = 7;

私人无效startAnimations(){
    //使用ImageView的不布局。
    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};

    //如果它是不一样的运动,你需要创建不同的布局
    动画snowMov1 = AnimationUtils.loadAnimation(这一点,R.layout.snowimg1);
    动画snowMov2 = AnimationUtils.loadAnimation(这一点,R.layout.snowimg2);
    动画snowMov3 = AnimationUtils.loadAnimation(这一点,R.layout.snowimg3);
    动画snowMov4 = AnimationUtils.loadAnimation(这一点,R.layout.snowimg4);
    动画snowMov5 = AnimationUtils.loadAnimation(这一点,R.layout.snowimg5);
    动画snowMov6 = AnimationUtils.loadAnimation(这一点,R.layout.snowimg6);

    动画movArray [] = {snowMov1,snowMov2,snowMov3,snowMov4,snowMov5,snowMov6};

    //开始运动动画。
    startMovement(snowArray,movArray);
}

私人无效startMovement(ImageView的imgArray [],动画movArray []){
    //相同长度,因此不会有问题...
    INT长度= imgArray.length;
    的for(int i = 0; I<长度;我++){
        movArray [I] .reset段();
        movArray [I] .setFillAfter(真正的);
        movArray [I] .setAnimationListener(本);
        movArray [I] .setRepeatCount(REPEAT_COUNT);
        movArray [I] .setRepeatMode(REPEAT_MODE);

        //启动动画
        imgArray [I] .startAnimation(movArray [I]);
    }
}
 

您需要做的随机运动的动画文件,这是没有测试,以便林不知道,如果它的工作原理......我希望它能帮助,至少我试过了。

编辑:

不要急躁,帮助将很快到来,如果我的方法是行不通的!你只需要等待的人...

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 extends 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...

这篇关于显示多个图像动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆