Android 显示多个图像动画
我想显示一个背景图像和多个像“降雪”场景一样向下移动的图像,那么我怎么做呢?背景图像不应该移动,只有上面的小图像应该向下移动。我怎么做 更新--> 我已经在屏幕上显示了图像,但它们都是同时出现的,但我想显示在不同时间出现的图像。我该怎么做?嘿,请建议一些方法。这是正确的方法吗?如果不是,请建议我正确的方法 这是我的密码:Android 显示多个图像动画,android,android-2.2-froyo,Android,Android 2.2 Froyo,我想显示一个背景图像和多个像“降雪”场景一样向下移动的图像,那么我怎么做呢?背景图像不应该移动,只有上面的小图像应该向下移动。我怎么做 更新--> 我已经在屏幕上显示了图像,但它们都是同时出现的,但我想显示在不同时间出现的图像。我该怎么做?嘿,请建议一些方法。这是正确的方法吗?如果不是,请建议我正确的方法 这是我的密码: public class AnimationActivity extends Activity implements AnimationListener { /**
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" />
main.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>
您可以为所有图像添加动画,如下所示:
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]);
}
}
private final int REPEAT\u COUNT=1;
专用最终整数重复模式=7;
私有void 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};
//如果不是相同的移动,则需要创建不同的布局
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);
动画movArray[]={snowMov1、snowMov2、snowMov3、snowMov4、snowMov5、snowMov6};
//启动运动动画。
开始移动(雪地阵列、移动阵列);
}
私有void开始移动(ImageView imgArray[],动画movArray[]{
//长度相同,所以没有问题。。。
int length=imgaray.length;
for(int i=0;i
你将需要在动画文件中随机移动,这是没有测试,所以我不知道它是否工作。。。我希望至少我试过了
编辑:
别急,如果我的方法不起作用,很快就会有帮助的!,你只需要等待,伙计…嘿,有人知道这个plz建议了什么吗………代码有用吗?如果需要,请将日志粘贴到pastebin.com;man;)我只是在想。如果我们需要更多的图像,那么为每个图像做线性布局不是很糟糕吗?你认为呢?我也遇到了同样的问题。你在Geetanjali做了什么改变