android-> 代码添加视图 addContentVIew

@Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);

	TextView tv = new TextView(this);
	FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
	FrameLayout.LayoutParams.WRAP_CONTENT,
	FrameLayout.LayoutParams.WRAP_CONTENT);
	// 设置广告出现的位置(悬浮于顶部)
	params.topMargin = 0;
	params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;

	tv.setText("我擦擦擦...dynamic layout");
	addContentView(tv, params);
	// setContentView(tv);
}

如果是 service 可以用 

getWindow().addContentView(l1, params);

 

猜你喜欢

转载自mft.iteye.com/blog/2324955