Droid: How to reorder a linearlayouts contents pro

2020-03-04 08:25发布

问题:

I have a scrollview with a list of buttons. I want to have the instructions at the beginning of this list when the app is first used, but then move the instructions to the end off screen after the user has used it once as the instructions won't really be needed again but I still want them accessible. I have no idea where to start!

Edit: Different explanation as requested.

My main layout has a table. The bottom row is a HorizontalScrollView, containing a LinearLayout, containing 6 Buttons. If we call these Buttons 1, 2, 3, 4 ,5 ,6 as they are ordered in the .xml layout, I want in code to be able to reorder them to "6, 1, 2, 3, 4, 5".

回答1:

Just find your views then removethen from linearlayout and add by new order.

ln1= (LinearLayout)findViewById(R.id.ln1);

    btn1= (Button)findViewById(R.id.button1);
    btn2= (Button)findViewById(R.id.button2);
    btn3= (Button)findViewById(R.id.button3);
    btn4= (Button)findViewById(R.id.button4);
    btn5= (Button)findViewById(R.id.button5);
    btn6= (Button)findViewById(R.id.button6);

    ln1.removeAllViews();

    ln1.addView(btn6);
    ln1.addView(btn1);
    ln1.addView(btn2);
    ln1.addView(btn3);
    ln1.addView(btn4);
    ln1.addView(btn5);