0

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?

user6191359
  • 69
  • 1
  • 9

1 Answers1

0

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.

Abhishek
  • 2,959
  • 2
  • 17
  • 24
  • Ok, I see how that could be useful, but what if I wanted to do something else, like change the background color continuously? – user6191359 Apr 13 '16 at 01:22
  • Is there a way to write in non-event-based methods? – user6191359 Apr 13 '16 at 01:23
  • You can use `Transition Drawable` to accomplish that – Abhishek Apr 13 '16 at 01:24
  • http://stackoverflow.com/questions/2614545/animate-change-of-view-background-color-in-android – Abhishek Apr 13 '16 at 01:24
  • Periodic call to a method call can be accomplished by several means, see here http://stackoverflow.com/questions/2614545/animate-change-of-view-background-color-in-android What do you mean my non event based? – Abhishek Apr 13 '16 at 01:29
  • By that I meant something that runs all the time and not just fired by an event listener – user6191359 Apr 13 '16 at 01:41
  • Well, go through the link I have provided in answer, it explains how to run a handler in background. You can run it in background for as long as you want, without hindering your main thread. Moreover, you don't need a listener to run a handler, you can start it whenever you want. – Abhishek Apr 13 '16 at 01:44