2011-07-25 38 views
3

我想显示一个背景图像和多个图像像“降雪”场景一样向下移动,所以我该怎么做?背景图像不应该移动,只有小图像应该掉下来。我这样做?显示多个图像动画

更新 - > 我已经显示在屏幕上的图像,但他们都在同一时间来了,但我想显示图像在不同的时间,我怎么能做到这一点未来哎请建议一些way.is这个吧?这样如果还是不行,请给我建议以正确的方式....

这里是我的代码:

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) 
    { 
    } 
} 

这里是动画布局文件:

<?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" /> 

主.xml文件

<?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>  
+0

喂任何人都知道这PLZ提出好的建议。 ........ – Geetanjali

回答

3

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

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]); 
    } 
} 

你需要做随机运动的动画文件,这不是测试,因此我不是当然,如果它的工作......我希望它至少有助于我尝试。

编辑:

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

+0

kim正在尝试...... – Geetanjali

+0

ya ofcourse ..... – Geetanjali

+0

做了代码工作吗?将日志粘贴到pastebin.com中,如果需要的话;) – jmsalcido