在SurfaceView的表层显示一个EditText,可以通过ViewGroup来实现:
public class GroupView extends ViewGroup {
static public EditText editText = null;
ViewGroup vGroup = new ViewGroup(getContext()) {
// @Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
final View backView = getChildAt(0);
backView.setVisibility(View.VISIBLE);
backView.layout(0, 0, 205, 106);
}
};
public GroupView(Context context, ClickSurfaceView clickSurface) {
super(context);
editText = new EditText(context);
editText.setBackgroundDrawable(null);
vGroup.addView(editText);
this.addView(clickSurface);
this.addView(vGroup);
}
// @Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
final View backView = getChildAt(0);
backView.setVisibility(View.VISIBLE);
backView.layout(0, 0, 800, 480);
final ViewGroup editText = (ViewGroup) getChildAt(1);
editText.setVisibility(View.VISIBLE);
editText.layout(62, 24, 267, 120);
}
}
在其他类中实例化SurfaceView后,调用
GroupView groupView = new GroupView(this, clickSurface);
setContentView(groupView);