Programmatically reorder RelativeLayout
<p>I'm trying to create a word jumble game where you drag a letter right or left in the jumbled word and the letters swap. What is the best way to reorder items in a RelativeLayout programmatically so when the letter is dragged left the letters that the tile passes are positioned to the right of the dragged letter.</p>

<p>I've tried something like this as a basic test.</p>

<pre><code>public static void moveTile(Tile tile, int x, RelativeLayout parent) {
    if (x &lt; tile.getWidth()) {
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.LEFT_OF, tile.getId() - 1);
        tile.setLayoutParams(params);

        RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        p.addRule(RelativeLayout.RIGHT_OF, tile.getId());
        Tile t = (Tile) parent.findViewById(tile.getId() - 1);
        t.setLayoutParams(p);
    }
    parent.invalidate();
}
</code></pre>

<p>But this causes the app to crash with an error about "Circular dependancies cannot exist in a RelativeLayout" which I understand but I'm just not sure what other way to do this.</p>

<p>Any help will be much appreciated.</p>
