androidandroid-studioprogram-entry-pointevent-based-programming

Android Studio - access main loop


mainly just looking for the place where I can call a method every single loop. I'd like to increase/decrease the Y of a button over a period of time. Can this be done without an event system?


Solution

  • You can use Android Animations, it's the easiest approach for what I think you need to implement.

    Check out: http://cogitolearning.co.uk/?p=952

    Overview

    Create an animation XML file, specify toYDelta and duration as required.

    Then load the animation and start it when required,

    Animation animation = AnimationUtils.loadAnimation(this, R.anim.animation); animBtn.startAnimation(animation);

    To call a method for each iteration of a loop,

    Look here: http://www.mkyong.com/java/how-to-run-a-task-periodically-in-java/

    My personal choice is using a handler: http://www.mkyong.com/java/how-to-run-a-task-periodically-in-java/

    Morever, if you are willing to cause a delay in your main thread to delay method calls, I would advice against that.