为什么我的观点不可见?

时间:2011-09-07 15:31:17

标签: android view opengl-es android-linearlayout

我正在尝试在我的GLSurfaceView上创建另一个视图,我之前设法做到了这一点,但由于某种原因,这一次没有任何可见。我在代码中做了所有这些,但下面是它应该如何使用XML:

setContentView(R.layout.main);
adLinearLayout = (LinearLayout)findViewById(R.id.AdLinearLayout);

//If ad is found on server...Do this (view is passed into the method)
LayoutParams layout = new LayoutParams(adLinearLayout.getMeasuredWidth(), (adLinearLayout.getMeasuredWidth()*10)/64);
adView.setLayoutParams(layout);
adLinearLayout.removeAllViews();
adLinearLayout.addView(adView);

我对此的解释是:

glView = new GLSurfaceView(this);
glView.setRenderer(this);
setContentView(glView);
adLinearLayout = new LinearLayout(this);
adLinearLayout.setGravity(Gravity.CENTER | Gravity.BOTTOM);
this.addContentView(adLinearLayout, new LayoutParams(480, 150));

//If ad is found on server...Do This  (view is passed into the method)
LayoutParams layout = new LayoutParams(adLinearLayout.getMeasuredWidth(), (adLinearLayout.getMeasuredWidth()*10)/64);
view.setLayoutParams(layout);
adLinearLayout.removeAllViews();
adLinearLayout.addView(view, new LayoutParams(LayoutParams.WRAP_CONTENT ,LayoutParams.WRAP_CONTENT));

虽然屏幕上的视图从未显示,但是有什么东西丢失了吗?

1 个答案:

答案 0 :(得分:0)

您需要使用framelayout将2个视图堆叠在一起。

我不确定你之前是如何与linearlayout完成重叠的。但是根据定义,LinearLayout用于以水平或垂直顺序组合子视图。

关于框架布局,这是来自android docs

  

子视图以堆栈形式绘制,包含最近添加的子视图   在上面。 FrameLayout的大小是其最大子项的大小   (加填充),可见或不可见(如果FrameLayout的父级允许)。

你也可以与RelativeLayout实现一些重叠,但FrameLayout是正确的方法。