Onlayout méthode sur la mise en page personnalisée extension RelativeLayout

Quelle est la bonne façon de remplacer onLayout méthode dans une mise en page personnalisée à l'extension de la RelativeLayout?
Je suis en train de placer tous les points de vue dans le tri d'un tableau. L'idée est de remplir une ligne avec ImageViews jusqu'à ce qu'il est plein et puis continuer dans la nouvelle ligne.

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);

        int idOfViewToTheLeft = 1;

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(getContext(),);

        ImageView bookmark;
        for(int counter = 1; counter < getChildCount(); counter++) {
            bookmark = (ImageView) findViewById(counter);
            if(counter > 1) {
               if(this.getWidth() > (bookmark.getLeft() + bookmark.getWidth())) {
                   params.addRule(RelativeLayout.RIGHT_OF, bookmark.getId() - 1);
               } else {
                   params.addRule(RelativeLayout.BELOW, idOfViewToTheLeft);
                   idOfViewToTheLeft = bookmark.getId();
               }
            }

            bookmark.setScaleType(ScaleType.CENTER_CROP);
        }
    }
    }

OriginalL'auteur lpandzic | 2011-02-13