We provide complete mobile and web apps development solutions

Monday, October 1, 2012

Animations in Android

Animations:


2 types

property animation
view animation

property animation:

an animation defined in xml that modifies the properties of color, alpha values over specified amount of time.

View Animation:

frame animation: animation is defined in xml file that shows a sequence of images in order.
(like a film)

Tween Animation:
Tween animation creates an animation by performing a series of transformations on a single image.

AlphaAnimation: controls the tranperancy changes.
RotateAnimation: controls the rotations.
ScaleAnimation: Controls the growing and shrinking
TranslateAnaimation: Controls the position changes.

Attributes:

<alpha>attributes:
android:fromAlpha, android:toAlpha

<rotate> attributes:
android:fromDegrees, android:toDegrees
<scale> attributes:
android:fromXScale, android:toXScale
android:fromYScale, android:toYScale
<translate> attributes:
android:fromXDelta, android:toXDelta
android:fromYDelta, android:toYDelta




MainActivity.java

package com.example.animation;


import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.Im;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.view.Menu;
import android.widget.ImageView;

public class MainActivity extends Activity {
ImageView im;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         im=(ImageView)findViewById(R.id.imageView1);
       
        im.setBackgroundResource(R.anim.tom);
       /* AnimationDrawable ad=(AnimationDrawable)im.getBackground();
        ad.start();
        */
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        // TODO Auto-generated method stub
        super.onWindowFocusChanged(hasFocus);
       
         AnimationDrawable frameAnimation =
                    (AnimationDrawable) im.getBackground();
                     if(hasFocus) {
                         frameAnimation.start();
                     } else {
                         frameAnimation.stop();
    }
    }

res/anim/tom.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
   
<item android:drawable="@drawable/cat_eat0000" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0002" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0003" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0004" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0005" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0006" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0007" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0008" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0009" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0010" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0011" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0012" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0013" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0014" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0015" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0016" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0017" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0018" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0019" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0020" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0021" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0022" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0023" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0024" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0025" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0026" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0027" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0028" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0029" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0030" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0031" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0032" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0033" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0034" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0035" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0036" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0037" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0038" android:duration="200"/>
<item android:drawable="@drawable/cat_eat0039" android:duration="200"/>

</animation-list>

res/layout/activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >



    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
       
        />

</LinearLayout>










Seo Directory List

0 coment�rios:

Post a Comment

Online Training

Your Name :
Your Email: (required)
Your Message: (required)

Powered by Blogger.

Recent Posts

Find Us On Facebook

Popular Posts