Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To address your trouble with initialization (I've had much trouble in the past with this myself): If I need to know when a view's layout is complete, I give it a runnable in Activity.onCreate() then call that runnable from View.onSizeChanged(). I've come to use this pattern quite a bit and I've found it very reliable. You just need to remember to only call the runnable from onSizeChanged() if the new width and height are greater than 0 and if they are not equal to the old width and height.</p> <p>So in your activity:</p> <pre><code>public void onCreate() { ... yourView.setLayoutRunnable(new Runnable() { @Override public void run() { //do post-layout stuff... } }); ... } </code></pre> <p>and in your view:</p> <pre><code>public Runnable layoutRunner; public void setLayoutRunnable(Runnable runner) { layoutRunner = runner; } @Override public void onSizeChanged(int w, int h, int oldw, int oldh) { if (w &gt; 0 &amp;&amp; h &gt; 0 &amp;&amp; (w != oldw || h != oldh)) { if (layoutRunner != null) layoutRunner.run(); } } </code></pre> <p>If you have multiple views that all need to have their layouts finished before you do your stuff, you have to keep a count as you get the notifications so you know when they're done.</p> <p>And regarding your topic in general, I implemented something similar to your radio button concept in a game I wrote, but I decided to override View from scratch to do it. I had all options for a set in a single view, so really I replaced the RadioGroup view rather than the RadioButton view. Each option had a value and an extent. I always used text, but images would work just as easily. Then I just tracked the taps and drags relative to the extents of the options and moved the "selector" on a timed handler (a la animations in javascript).</p>
 

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