This exercise have the almost same effect as in the last exercise "Handle Animation event, AnimationListener".
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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/icon"
/>
</LinearLayout>
package com.exercise.AndroidAnimation;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class AndroidAnimationActivity extends Activity {
ImageView image;
Animation animationFadeIn, animationFadeOut;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image = (ImageView)findViewById(R.id.image);
animationFadeIn = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
animationFadeOut = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
animationFadeIn.setAnimationListener(animationInListener);
animationFadeOut.setAnimationListener(animationOutListener);
image.startAnimation(animationFadeIn);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
image.clearAnimation();
}
AnimationListener animationInListener
= new AnimationListener(){
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
image.startAnimation(animationFadeOut);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}};
AnimationListener animationOutListener
= new AnimationListener(){
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
image.startAnimation(animationFadeIn);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}};
}
Download the files.
next:
- Implement slide-in and slide-out animation
Thank you for reading this article Android pre-defined Animation Resources With URL https://x-tutorials.blogspot.com/2011/09/android-pre-defined-animation-resources.html. Also a time to read the other articles.
0 comments:
Write your comment for this article Android pre-defined Animation Resources above!