为什么我的视图不可见?
我正在尝试在 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));
但这永远不会显示在屏幕上的视图中,是否缺少某些内容?
I am trying to create another view on top of my GLSurfaceView, I have managed to do this before but for some reason nothing is visible this time round. I do all this in code but below is how it should work with 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);
And my interpretation of this is:
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));
This never shows in the view on the screen though, is there something missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用框架布局将 2 个视图堆叠在一起。
我不确定你之前是如何与线性布局重叠的。但根据定义,LinearLayout 用于按水平或垂直顺序组装子视图。
关于框架布局,这是来自android文档
您还可以使用RelativeLayout 实现一些重叠,但FrameLayout 是正确的方法。
You need to use a framelayout to stack 2 views on top of each other.
Im not sure how you got overlapping done with linearlayout earlier. But by definition LinearLayout is used to asseble child views in either horizontal or vertical order.
About the frame layout, this is from the android docs
You could also achieve some overlapping with a RelativeLayout but FrameLayout is the proper way to go.