Search code examples
androidanimationaccelerometer

android animation change with accelerometer movement


I want to change animation with the movement of Accelerator. If there is no movement of accelerometer the I want to display one animation. If there is movement of accelerometer then the other animation must be displayed. I am using 2 .xml files having animationlist tags(which are in .xml file which is in the res->drawable folder)and having tags representing 5 images with durations specified in each item tags in the animationlist tag. Like this I am having two .xml files each representing two different animations. With the movement of accelerometer these two changes in animations must occur. Can anyone suggest me the code ?


Solution

  • I resolved by the following steps:

    1. Created two image views which refers to same image and then set the 'setBackgroundResource' to those two images in which one image view has 'setBackgroundResource' to one xml file and the other image view has 'setBackgroundResource' to the other xml file.
    2. Assigned the two image view object to AnimationDrawable object by getting the background drawable of the two image view and assigning them to AnimationDrawable objects.
    3. Called in that particular image which I want to animate when phone is moving by placing in the loop when the speed is greater than the threshold, and the other animation outside when there is no movement of the phone

      It worked! You can start here This code provides a good understanding of phone movement http://www.clingmarks.com/how-to-detect-shake-motion-on-android-phone/25.