This example let you shake or animation your view on some event described.
Algorithm:
1.) Create a new project by File-> New -> Android Project name it ShakeAnimationExample.
2.) You will see some default code into your main.xml, strings.xml and android manifest file.
3.) Write following into main.xml file:
4.) Create and Write following into anim/shake.xml:
5.) Create and Write following into anim/cycle_7.xml:
Steps:
1.) Create a project named ShakeAnimationExample and set the information as stated in the image.
Build Target: Android 1.6
Application Name: ShakeAnimationExample
Package Name: com.example. ShakeAnimation
Activity Name: ShakeAnimationExample
Min SDK Version: 4
2.) Open ShakeAnimationExample.java file and write following code there:
package com.example.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 ShakeAnimation extends Activity implements View.OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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();
}
}
3.) Compile and build the project.
4.) Run on 1.6 simulator for the output.
Read rest of entry
Algorithm:
1.) Create a new project by File-> New -> Android Project name it ShakeAnimationExample.
2.) You will see some default code into your main.xml, strings.xml and android manifest file.
3.) Write following into main.xml file:
4.) Create and Write following into anim/shake.xml:
5.) Create and Write following into anim/cycle_7.xml:
Steps:
1.) Create a project named ShakeAnimationExample and set the information as stated in the image.
Build Target: Android 1.6
Application Name: ShakeAnimationExample
Package Name: com.example. ShakeAnimation
Activity Name: ShakeAnimationExample
Min SDK Version: 4
2.) Open ShakeAnimationExample.java file and write following code there:
package com.example.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 ShakeAnimation extends Activity implements View.OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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();
}
}
3.) Compile and build the project.
4.) Run on 1.6 simulator for the output.






