0

i m new to this android application development field i went through the code that would provide shaking feature but i m unable to understand that for writing this shaking code I have to create new project or i can add this code in my existing app like gallery (example given in tutorials of android development) If so then how??? plzzzz reply

swati sinha
  • 53
  • 1
  • 10

2 Answers2

2

Hello swati sinha You hav to use android shake animation. here some hints suppose you want to add shake animation to Edittext.

Animation animationShake= AnimationUtils.loadAnimation(this, R.anim.shake); 
if(editext.getText().lenght()==0){
edittext.startAnimation(animationShake);
}

and shake.xml looks like

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
android:fromXDelta="0" android:toXDelta="10" android:duration="1000" 
android:interpolator="@anim/cycle_7" />

and cycle_7.xml looks like

<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"      android:cycles="7" />

both cycle_7 and shake xml file shud be under res/anim folder. if You find my answer useful chek as accepted answer

Krishna Shrestha
  • 1,664
  • 14
  • 38
1

Swati, if you follow this example: Sample 1 you can implement that in the same class where you want the shake to be detected

On the other hand, if you follow this example: Sample 2 you will need to create a new 'class' and then writing that code.

Do let me know if you have any questions

Community
  • 1
  • 1
Soham
  • 4,842
  • 3
  • 29
  • 47