我是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);
}
}
主要的.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>