Tuesday, May 8, 2012

Android :Ringing Bell (Pendulum Animation)

To achieve the pendulum animation, we need to have a animation xml file,which can be load in the code to perform pendulum animation.

pendulum.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="15" android:toDegrees="-15" android:pivotX="50%"
    android:pivotY="0%" android:duration="400" android:repeatMode="reverse"
    android:repeatCount="-1" />

MainActivity
public class MainActivity extends Activity {
    private View mPendulum;

    private Animation mAnimation;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.move);
        mPendulum = findViewById(R.id.pendulum);
        mAnimation = AnimationUtils.loadAnimation(this, R.animator.pendulum);
    }

    @Override
    public void onResume() {
        super.onResume();
        mPendulum.startAnimation(mAnimation);
    }
}

just run, we can have pendulum motion or ringing bell effect :)

Output

Source Code : Here

4 comments :

  1. Hi Vardhan,

    Really useful example. I am facing some issues so can you please help me???? Can you please send me this project in a zip file???? my email id is alibinabid@gmail.com

    ReplyDelete
  2. When it stop it stop sharply but not in smooth way

    ReplyDelete
    Replies
    1. any update on this. same happens to me, stops sharply.

      Delete