Sunday, 20 January 2013

Android animation

Hello Droid Guys,

In my previous article or blog , i had explain how to show shake animation
in android. Now , in this blog I am covering the other animation.
like:
1, left to right animation in android
2. right to left animation in android
3. fade out animation in android
4. zoom in animation in android
5. slide up animation in android
6. slide down animation in andriod

1.res/anim/slideoutleft.xml

<?xml version="1.0" encoding="utf-8"?>

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@integer/fastAnim"
    android:fromXDelta="0"
    android:interpolator="@android:anim/overshoot_interpolator"
    android:toXDelta="-100%p" />

2. res/anim/slideinright.xml

    <?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="@integer/fastAnim"
        android:fromXDelta="100%p"
        android:interpolator="@android:anim/overshoot_interpolator"
        android:toXDelta="0" />

3.res/anim/fadeout.xml


<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@integer/fastAnim"
    android:fromAlpha="1.0"
    android:toAlpha="0.0" />


 Another link
 1. Shake animation in android

Android Shake animation

Hello Droid Friends,

This is my another android blog in which I am going to explain the Animation
effect(shake Animation ) in android. When you fill wrong input then instead of
showing the toast messege you can also shake the view.

shake animation

Steps :
1. Create a project with name "Shake animation" and package name
    "com.mukesh.shakeanimation".
2. add an "anim" folder inside the res folder.see the image below.

android shake animation
 
Source Code:

1. Activity Class:




package com.mukesh.shakeanimation;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;

public class MainActivity extends Activity implements View.OnClickListener {

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  View loginButton = findViewById(R.id.login);
  loginButton.setOnClickListener(this);
 }

 public void onClick(View v) {
  Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
     findViewById(R.id.pw).startAnimation(shake);
     Toast.makeText(this, "Wrong Password", Toast.LENGTH_SHORT).show();
 }

}


2) activity_main.xml




<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background="@drawable/blue_gradient"

    android:orientation="vertical"

    android:padding="10dip" >



    <TextView

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_marginBottom="10dip"

        android:text="Please enter your password:"

        android:textColor="@android:color/white"

        android:textStyle="bold" />



    <EditText

        android:id="@+id/pw"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:clickable="true"

        android:password="true"

        android:singleLine="true" />



    <Button

        android:id="@+id/login"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:background="@drawable/btn_active_pressed"

        android:padding="5dp"

        android:text="Login"

        android:textColor="@android:color/white"

        android:textStyle="bold" />



</LinearLayout>

3. res/anim/shake.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXDelta="0"
    android:interpolator="@anim/cycle_7"
    android:toXDelta="10" />

4. res/anim/cycle_7.xml

<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
    android:cycles="7" />



May this will helps someone.
Enjoy coding  :)


Following link also helps you :
1. left to right animation in android
2. right to left animation in android
3. fade out animation in android
4. zoom in animation in android
5. slide up animation in android
6. slide down animation in andriod

 

Copyright @ 2013 Android Developer Blog.