动态控件的创建有关问题
动态控件的创建问题
我想在原来的程序基础中动态新创建一个计时器 代码如下
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行程序就没问题
------解决方案--------------------
把setContentView改为addContentView
Chronometer chr=new Chronometer(this);
RelativeLayout layout=new RelativeLayout (this);
addContentView(layout);
layout.addView(chr, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
chr.start();
我想在原来的程序基础中动态新创建一个计时器 代码如下
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行程序就没问题
------解决方案--------------------
把setContentView改为addContentView
Chronometer chr=new Chronometer(this);
RelativeLayout layout=new RelativeLayout (this);
addContentView(layout);
layout.addView(chr, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
chr.start();