Create /res/anim/multianim.xml to embed three type of animation in one set.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<translate
android:fromYDelta="-100%p"
android:toYDelta="0"
android:duration="4000"
android:repeatCount="infinite"
android:repeatMode="restart"/>
<translate
android:fromXDelta="-50%p"
android:toXDelta="50%p"
android:duration="1000"
android:repeatCount="infinite"
android:repeatMode="reverse"/>
<alpha
android:fromAlpha="0.5"
android:toAlpha="1.0"
android:duration="500"
android:repeatCount="infinite"
android:repeatMode="reverse" />
</set>
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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>
main activity
package com.exercise.AndroidAnimTranslate;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class AndroidAnimTranslateActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView image = (ImageView)findViewById(R.id.image);
Animation multiAnim = AnimationUtils.loadAnimation(this, R.anim.multianim);
image.startAnimation(multiAnim);
}
}
Download the files.
No comments:
Post a Comment