从子视图切换FrameLayout中的视图

时间:2011-05-08 14:58:43

标签: android android-edittext android-linearlayout surfaceview android-framelayout

我目前有一个存储在FrameLayout中的SurfaceView(名为BoardView)。还有另一个LinearLayout(l1)存储在此FrameLayout(f1)中,其中包含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));
}

}

1 个答案:

答案 0 :(得分:1)

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

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

,编辑文字将位于顶部。

让我知道它是否有效。