开发者

Switch Between views in FrameLayout from a child view

开发者 https://www.devze.com 2023-03-03 14:14 出处:网络
I currently havea SurfaceView (named BoardView) that is being stored in a FrameLayout. There is another LinearLayout (l1) that is stored in this FrameLayout(f1) which contains an EditText. I want to b

I currently have a SurfaceView (named BoardView) that is being stored in a FrameLayout. There is another LinearLayout (l1) that is stored in this FrameLayout(f1) which contains an EditText. I want to be able to bring the EditText to the front from within my BoardView. Is this possible? I tried using getParent().bringChildToFront(); but it didn't work. Any ideas?

public class Board extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    //use a frame layout so you can also display a dialog box
    // allows more than one view to be used
    FrameLayout f1 = new FrameLayout(this);
    LinearLayout l1 = new LinearLayout(this);
    EditText edit = new EditText(this);

    l1.setOrientation(LinearLayout.VERTICAL);
    l1.setLayoutParams(new LayoutParams(Layo开发者_如何学运维utParams.WRAP_CONTENT, 
            LayoutParams.WRAP_CONTENT));
    edit.setText("Enter your name!");
    l1.addView(edit);

    f1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 
            LayoutParams.FILL_PARENT));
    f1.addView(l1);
    f1.addView(new BoardView(this));

    setContentView(f1);

    //setContentView(new BoardView(this));
}

}


Sounds rather silly, but try l1.bringToFront() and see if that works? Alternatively just add l1 second:

f1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 
            LayoutParams.FILL_PARENT));
    f1.addView(new BoardView(this));
    f1.addView(l1);

and the edit text will be on top.

Let me know if it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消