Skip to main content

Animation Demo in Android(Tween Animation)

This Animation Demo.....

Download This Code Click Here......

The view animation framework supports both tween and frame by frame animations, which can both be declared in XML. The following sections describe how to use both methods.

Tween animation

An animation defined in XML that performs transitions such as rotating, fading, moving, and stretching on a graphic.
file location:
res/anim/filename.xml The filename will be used as the resource ID.
compiled resource datatype:
Resource pointer to an Animation.
resource reference:
In Java: R.anim.filename In XML: @[package:]anim/filename
syntax:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@[package:]anim/interpolator_resource"
    android:shareInterpolator=["true" | "false"] >
    <alpha
        android:fromAlpha="float"
        android:toAlpha="float" />
    <scale
        android:fromXScale="float"
        android:toXScale="float"
        android:fromYScale="float"
        android:toYScale="float"
        android:pivotX="float"
        android:pivotY="float" />
    <translate
        android:fromXDelta="float"
        android:toXDelta="float"
        android:fromYDelta="float"
        android:toYDelta="float" />
    <rotate
        android:fromDegrees="float"
        android:toDegrees="float"
        android:pivotX="float"
        android:pivotY="float" />
    <set>
        ...
    </set>
</set>
The file must have a single root element: either an <alpha><scale><translate><rotate>, or <set>element that holds a group (or groups) of other animation elements (even nested <set> elements).
elements:
<set>
A container that holds other animation elements (<alpha><scale><translate><rotate>) or other <set> elements. Represents an AnimationSet.
attributes:
android:interpolator
Interpolator resource. An Interpolator to apply on the animation. The value must be a reference to a resource that specifies an interpolator (not an interpolator class name). There are default interpolator resources available from the platform or you can create your own interpolator resource. See the discussion below for more about Interpolators.
android:shareInterpolator
Boolean. "true" if you want to share the same interpolator among all child elements.

<alpha>



A fade-in or fade-out animation. Represents an AlphaAnimation.
attributes:
android:fromAlpha
Float. Starting opacity offset, where 0.0 is transparent and 1.0 is opaque.
android:toAlpha
Float. Ending opacity offset, where 0.0 is transparent and 1.0 is opaque.
For more attributes supported by <alpha>, see the Animation class reference (of which, all XML attributes are inherrited by this element).

<scale>



A resizing animation. You can specify the center point of the image from which it grows outward (or inward) by specifying pivotX and pivotY. For example, if these values are 0, 0 (top-left corner), all growth will be down and to the right. Represents a ScaleAnimation.
attributes:
android:fromXScale
Float. Starting X size offset, where 1.0 is no change.
android:toXScale
Float. Ending X size offset, where 1.0 is no change.
android:fromYScale
Float. Starting Y size offset, where 1.0 is no change.
android:toYScale
Float. Ending Y size offset, where 1.0 is no change.
android:pivotX
Float. The X coordinate to remain fixed when the object is scaled.
android:pivotY
Float. The Y coordinate to remain fixed when the object is scaled.
For more attributes supported by <scale>, see the Animation class reference (of which, all XML attributes are inherrited by this element).

<translate>



A vertical and/or horizontal motion. Supports the following attributes in any of the following three formats: values from -100 to 100 ending with "%", indicating a percentage relative to itself; values from -100 to 100 ending in "%p", indicating a percentage relative to its parent; a float value with no suffix, indicating an absolute value. Represents a TranslateAnimation.
attributes:
android:fromXDelta
Float or percentage. Starting X offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element width (such as "5%"), or in percentage relative to the parent width (such as "5%p").
android:toXDelta
Float or percentage. Ending X offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element width (such as "5%"), or in percentage relative to the parent width (such as "5%p").
android:fromYDelta
Float or percentage. Starting Y offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element height (such as "5%"), or in percentage relative to the parent height (such as "5%p").
android:toYDelta
Float or percentage. Ending Y offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element height (such as "5%"), or in percentage relative to the parent height (such as "5%p").
For more attributes supported by <translate>, see the Animation class reference (of which, all XML attributes are inherrited by this element).

<rotate>



A rotation animation. Represents a RotateAnimation.
attributes:
android:fromDegrees
Float. Starting angular position, in degrees.
android:toDegrees
Float. Ending angular position, in degrees.
android:pivotX
Float or percentage. The X coordinate of the center of rotation. Expressed either: in pixels relative to the object's left edge (such as "5"), in percentage relative to the object's left edge (such as"5%"), or in percentage relative to the parent container's left edge (such as "5%p").
android:pivotY
Float or percentage. The Y coordinate of the center of rotation. Expressed either: in pixels relative to the object's top edge (such as "5"), in percentage relative to the object's top edge (such as"5%"), or in percentage relative to the parent container's top edge (such as "5%p").
For more attributes supported by <rotate>, see the Animation class reference (of which, all XML attributes are inherrited by this element).

example:



XML file saved at res/anim/property.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="5.6"
            android:toXScale="2"
            android:fromYScale="5.0"
            android:toYScale="0.0"
            android:pivotX="25%"
            android:pivotY="50%"
            android:duration="500" />
        <rotate
            android:fromDegrees="0"
            android:toDegrees="-90"
            android:toYScale="0.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="700" />
    </set>
</set>
This application code will apply the animation to an ImageView and start the animation:
import android.os.Bundle;
import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.app.Activity;
import android.view.Menu;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
//O@K Tech..
public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.animator);
        ImageView img = (ImageView)findViewById(R.id.imageView1);
        Animation amnt = AnimationUtils.loadAnimation(this,R.anim.property);
        img.startAnimation(amnt);
       
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Comments

Popular posts from this blog

Audio Recording in Android

Simple State Diagram for Media Recorder... Here Sequence of Method call is as per state diagram of media Recorder .... Otherwise Invalid sate call Error will be Occur........ Steps: 1) Also her two permission add in Android manifest file <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 2) This is java file coding  audiorecording.java package com.example.recording; import java.io.File; import java.io.FileDescriptor; import android.media.MediaRecorder; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import

Login Application using Database with dialog demo

Follow Below Steps for make simple login applicaiton in Android using database with Dialog demo. 1)DataBaseDemoActivity.java This file diplay login page and trasfer two edit text data into second activity........  package database.co.in; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class DataBaseDemoActivity extends Activity implements OnClickListener {     /** Called when the activity is first created. */     EditText mtxt_email, mtxt_password;     Button mLogin; @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);         mtxt_email = (EditText)findViewById(R.id.editEmail_id);         mtxt_password = (EditText)findViewById(R.id.editPassword);         mLogin = (Button)findViewById(R.id.but