我想在原来的程序基础中动态新创建一个计时器 代码如下
public class SurfaceViewAcitvity extends Activity{
    AnimView mAnimView = null; 
    @Override
    public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);                  Chronometer chr=new Chronometer(this);
RelativeLayout layout=new RelativeLayout (this);
setContentView(layout); 
layout.addView(chr, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
chr.start();          ......
编译器没有错误提示,但是一运行起来就崩溃,求高手指点迷津!删除掉那5行程序就没问题

解决方案 »

  1.   

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    // 获取屏幕宽高
    Display display = getWindowManager().getDefaultDisplay();

    // 显示自定义的游戏View

    mAnimView = new AnimView(this,display.getWidth(), display.getHeight());
    setContentView(mAnimView);

    Chronometer chr=new Chronometer(this);
    RelativeLayout layout=new RelativeLayout (this);
    setContentView(layout); 
    layout.addView(chr, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    chr.start();
    我把这5行加到后面之后,原来的画面又都看不到了
      

  2.   

    把setContentView改为addContentViewChronometer chr=new Chronometer(this);
     RelativeLayout layout=new RelativeLayout (this);
     addContentView(layout);  
    layout.addView(chr, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
     chr.start();
      

  3.   

    终于成功了!谢谢各位! 原来把setContentView 换成this.addContentView()就行了
    (自导自演吗...囧rz)