>"... to call removeAllViews() on the RelativeLayout and simply rebuild
>all of its child widgets in the desired order..."
>
>when i called them? when I click the button? hmm..do you have any
>tutorial or sample for this one? couse i'm  a newbie in android
>developer ^^

Correct, when you click the button. Assuming you have built the original UI 
using the designer built into Eclipse, and let's assume you have given the base 
layout an id of 'base_layout', the buttons ids of 'up_button' and 'down_button' 
and the image an id of 'my_image', your code for rebuilding the UI would go 
something like this (apologies for line wrapping): 

public void onClick(View v) 
{
    if (v.getId() == R.id.up_button) 
    {
        RelativeLayout baseLayout = 
(RelativeLayout)findViewById(R.id.base_layout); 

        // Must grab references to child widgets *before* calling 
removeAllViews(). 
        Button upButton = (Button)findViewById(R.id.up_button); // Or just use 
ā€˜v’ in this case. 
        Button downButton = (Button)findViewById(R.id.down_button); 
        ImageView imageToMove = (ImageView)findViewById(R.id.my_image); 

        // *Now* it's safe to remove them, as we keep them in existence by 
        // our references above. 
        baseLayout.removeAllViews(); // Clears all widgets. 

        // Grab existing layout params - we want to keep the same dimensions 
        // but reset any rules and add our own replacement rules for 
sequencing. 

        RelativeLayout.LayoutParams params = 
(RelativeLayout.LayoutParams)imageToMove.getLayoutParams(); 
        params = new RelativeLayout.LayoutParams(params.width, params.height); 
// Same dimensions, no rules. 
        imageToMove.setLayoutParams(params); // No rules = at the top now. 

        params = (RelativeLayout.LayoutParams)upButton.getLayoutParams(); 
        params = new RelativeLayout.LayoutParams(params.width, params.height); 
// Same dimensions, no rules. 
        params.addRule(RelativeLayout.BELOW, imageToMove.getId() ); 
        upButton.setLayoutParams(params); // Now below image. 

        params = (RelativeLayout.LayoutParams)downButton.getLayoutParams(); 
        params = new RelativeLayout.LayoutParams(params.width, params.height); 
// Same dimensions, no rules. 
        params.addRule(RelativeLayout.BELOW, upButton.getId() ); 
        downButton.setLayoutParams(params); // Now below upButton. 

        baseLayout.requestLayout(); // We changed stuff, need it to lay itself 
out again. 

    }

}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to