I'm developing an Android 2.2 application.
I want to move an image from left side of the screen to the right side of the screen.
How can I do that? I've read that I have to add this image to a ListView or to a GridView to setup this animation.
UPDATE
I've created the following files:
anim/translate_right
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<translate
android:fromXDelta="-100%p"
android:toXDelta="0"
android:duration="5000" />
</set>
anim/ship_layout_controller
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="10%"
android:animationOrder="reverse"
android:animation="@anim/translate_right" />
layout/startpage
<?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">
<TextView
android:id="@+id/appNameTextView"
android:text="@string/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40px"/>
<Button
android:id="@+id/PlayButton"
android:text="@string/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40px"/>
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/greekShip"
android:persistentDrawingCache="animation|scrolling"
android:layoutAnimation="@anim/ship_layout_controller"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/greekship"
android:maxWidth="176px"
android:maxHeight="87px"
android:layout_x="-300px"/>
</AbsoluteLayout>
</LinearLayout>
StartActivity.java
public class StartActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.startpage);
}
@Override
protected void onResume() {
super.onResume();
ImageView ship = (ImageView)findViewById(R.id.greekShip);
ship.startAnimation(AnimationUtils.loadAnimation(this, R.anim.translate_right));
}
}
But it doesn't work.