为什么我的视图不可见?

发布于 2024-12-03 07:19:01 字数 1193 浏览 4 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执笔绘流年 2024-12-10 07:19:02

您需要使用框架布局将 2 个视图堆叠在一起。

我不确定你之前是如何与线性布局重叠的。但根据定义,LinearLayout 用于按水平或垂直顺序组装子视图。

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

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

您还可以使用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

Child views are drawn in a stack, with the most recently added child
on top. The size of the FrameLayout is the size of its largest child
(plus padding), visible or not (if the FrameLayout's parent permits).

You could also achieve some overlapping with a RelativeLayout but FrameLayout is the proper way to go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文