如何在android中移动图像像无尽的道路?

时间:2012-12-19 18:15:42

标签: android image animation infinite-loop

我是android的新手。我想开发一款移动汽车的应用程序。我想无休止地运行一个道路图像,以便用户会认为汽车正在移动。请帮助我。这是我迄今为止尝试过的,

Image_MoveActivity

package com.image;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class Image_moveActivity extends Activity {
    /** Called when the activity is first created. */
    private ImageView mScanner, mScanner1,mScanner2;
    private Animation mAnimation,mAnimation1, mAnimation2;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mScanner = (ImageView)findViewById(R.id.imageView1);
        mScanner1 = (ImageView)findViewById(R.id.imageView3);
        mScanner2 = (ImageView)findViewById(R.id.imageView4);
        mAnimation = new TranslateAnimation(0, 0, 0, 500);
        mAnimation1 = new TranslateAnimation(5, 5, 5, 500);
        mAnimation2 = new TranslateAnimation(5, 5, 5, 500);
        mAnimation.setDuration(10000);
        mAnimation.setFillAfter(true);
       mAnimation.setRepeatCount(Animation.INFINITE);
        mAnimation.setRepeatMode(Animation.INFINITE);
        mScanner.setAnimation(mAnimation);
        mScanner.setVisibility(View.VISIBLE);
    mAnimation1.setDuration(100);
        mAnimation1.setFillAfter(true);
       mAnimation1.setRepeatCount(Animation.INFINITE);
    mAnimation1.setRepeatMode(Animation.INFINITE);
    mScanner1.setAnimation(mAnimation);
    mScanner1.setVisibility(View.VISIBLE);
    mAnimation2.setDuration(100);
    mAnimation2.setFillAfter(true);
   mAnimation2.setRepeatCount(Animation.INFINITE);
mAnimation2.setRepeatMode(Animation.INFINITE);
mScanner2.setAnimation(mAnimation);
mScanner2.setVisibility(View.VISIBLE);
    }
}

main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" android:background="@drawable/road">


    <FrameLayout
        android:id="@+id/frameLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >


        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/road" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/player" android:layout_gravity="bottom" android:layout_marginLeft="100dp"/>

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/car2" android:layout_gravity="right"/>

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/car3" android:layout_gravity="top|center" android:layout_marginLeft="15dp"/>

    </FrameLayout>

</LinearLayout>

0 个答案:

没有答案