Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Move views around the screen
    primarykey
    data
    text
    <p>I have a custom view with an added method named moveView which changes the location of the view by a X pixels in Y direction when invoked. Now I want to have 6 of these views spread all over the screen and be in constant movement.</p> <p>What I have:</p> <ol> <li><strong><code>Handler</code></strong> (I need it for UI updates?)</li> <li><strong><code>ApplyMoveRunnable</code></strong> (implements Runnable. Constructor receives custom View, amount of pixels to move, and direction in which it will move)</li> <li>6 <strong>Threads</strong> (one for each view)</li> <li>6 <strong><code>MoveCalcRunnable</code></strong> (one for each thread. implements Runnable)</li> </ol> <p>What I tried: I tried creating my 6 views and then 6 Threads. Each of these threads' <code>MoveCalcRunnable</code> call the moveView() method within their respective views. This moveView() method calculates the amount of pixels the view will move and the direction in which it will move and sends this information to the <code>ApplyMoveRunnable</code> and then calls the <code>handler.post(applyMoveRunnable)</code>.</p> <p>Simply put, what happens is this:</p> <ol> <li>Instantiate <code>ApplyMoveRunnable applyMoveRunnable</code></li> <li>Instantiate <code>Handler handler</code>.</li> <li>Instantiate 6 <code>MoveCalcRunnable</code>'s.</li> <li>Create 6 threads, one for each view, each holding a <code>MoveCalcRunnable</code>.</li> <li>Start all threads.</li> </ol> <p>When I run this, at first I see my 6 views, but then one moves and nothing else happens.</p> <p>Here's the run() method for each of my <code>MoveCalcRunnable</code>:</p> <pre><code> @Override public void run() { Log.e(tag, "Thread locking directionAmountRunnable."); synchronized (applyMoveRunnable) { Log.e(tag, "Moving view."); myView.moveView(); } } </code></pre> <p>Can anyone help me get this to work? Or suggest a better, simpler, and/or more efficient way of doing this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload