Tweened Animation

Tweened Animation

/res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<Button android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="@string/hello"
		android:id="@+id/button1" />
	<ImageView android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:id="@+id/imageview1"
		android:src="@drawable/a" />
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:id="@+id/TextView1"
		android:text="Hello" android:textSize="40dp" />

</LinearLayout>

/res/anim/alphaeffect.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
	android:shareInterpolator="false"
	android:interpolator="@android:anim/accelerate_decelerate_interpolator">
	<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
		android:duration="5000">
	</alpha>
</set>

/res/anim/grow.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
	android:shareInterpolator="false">
	<scale android:pivotX="50%" android:pivotY="50%"
		android:fromXScale="1.0" android:fromYScale="1.0" android:toXScale="4.0"
		android:toYScale="4.0" android:duration="2500" />
	<scale android:startOffset="2500" android:duration="2500"
		android:pivotX="50%" android:pivotY="50%" android:fromXScale="1.0"
		android:fromYScale="1.0" android:toXScale="0.5" android:toYScale="0.5" />
</set>

/res/anim/hyperscpace_jump.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
	android:shareInterpolator="false">
	<scale android:interpolator="@android:anim/accelerate_decelerate_interpolator"
		android:fromXScale="1.0" android:toXScale="1.4" android:fromYScale="1.0"
		android:toYScale="0.6" android:pivotX="50%" android:pivotY="50%"
		android:fillAfter="false" android:duration="700" />
	<set android:interpolator="@android:anim/accelerate_interpolator"
		android:startOffset="700">
		<scale android:fromXScale="1.4" android:toXScale="0.0"
			android:fromYScale="0.6" android:toYScale="0.0" android:pivotX="50%"
			android:pivotY="50%" android:duration="400" />
		<rotate android:fromDegrees="0" android:toDegrees="-45"
			android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%"
			android:duration="400" />
	</set>
</set>

/res/anim/spin.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
	android:shareInterpolator="false">
	<rotate android:fromDegrees="0" android:toDegrees="360"
		android:pivotX="100%" android:pivotY="100%" android:duration="5000" />
</set>

/res/anim/spin.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
	android:shareInterpolator="false">
	<translate android:toXDelta="100" android:fillAfter="false"
		android:duration="2500" />
</set>

Activity file

package com.androidwork.tweenedanimationdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class TweenedAnimationDemoActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		ImageView spaceshipImage = (ImageView) findViewById(R.id.imageview1);

		Animation a = AnimationUtils.loadAnimation(getApplicationContext(),
				R.anim.translateanim);
		spaceshipImage.startAnimation(a);
		// spaceshipImage.startAnimation(hyperspaceJumpAnimation);
		TextView tv = (TextView) findViewById(R.id.TextView1);
		tv.startAnimation(a);

		// AlphaAnimation aa = new AlphaAnimation(context, attrs)

	}
}

Output

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s