0

我目前有一个存储在 FrameLayout 中的 SurfaceView(名为 BoardView)。在此 FrameLayout(f1) 中存储了另一个 LinearLayout (l1),其中包含一个 EditText。我希望能够从我的 BoardView 中将 EditText 放在前面。这可能吗?我尝试使用 getParent().bringChildToFront(); 但它没有用。有任何想法吗?

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(LayoutParams.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));
}

}

4

1 回答 1

1

听起来很傻,但试试看l1.bringToFront()是否有效?或者,只需添加l1第二个:

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

并且编辑文本将在顶部。

让我知道它是否有效。

于 2011-05-08T16:09:53.477 回答