Android的,无需XML布局添加新的视图 [英] Android, add new view without XML Layout

查看:95
本文介绍了Android的,无需XML布局添加新的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从人的经验性一点帮助。我希望这很容易。 我只是想表明新的视图(创建它的 XML布局)以上主程序的观点。 这是整合AdMob.com广告代码:

I need a little help from people with expirience. I hope it's easy. I just want to show new View (creating it without XML layouts) above main program's view. It's to integrate AdMob.com ad block:

我写了这样code:

AdView ad = new AdView(this); 
ad.layout(10, 10, 100, 100); 
ad.setVisibility(View.VISIBLE); 
ad.bringToFront(); 
ad.requestFocus(); 
ad.invalidate();

正如你看到的 - 没有任何帮助,没有窗户可见
是什么让我的错误? 谢谢!

As you see - nothing helped, no window visible
What do I make incorrectly? Thanks!

P.S。我在活动的onCreate(捆绑)取得,但我想在其他地方了。

P.S. I made in in Activity's onCreate(Bundle), but I tried in other locations too.

推荐答案

您还没有真正告诉系统什么或在哪里画它。你想看看您的活动为的setContentView(视图)的说明文件。如果你想获得此画在当前屏幕,看的对话框(和的setContentView 的说明文件)。

You haven't actually told the system to draw anything or where to draw it. You'll want to look at the documentation for setContentView(view) on your Activity. If you're trying to get this to draw over your current screen, look at the documentation for Dialog (and setContentView).

当我以编程方式创建任意的意见,以现有的布局中吸取,我通常会添加一个的FrameLayout 标签我的布局XML ,然后在code调用 findViewById(),那么我可以使用的FrameLayout 着眼于视图添加到( addView())。

When I'm programmatically creating arbitrary views to draw within an existing layout, I usually add a FrameLayout tag to my layout XML, then in the code call findViewById(), then I can use that FrameLayout view to add the view to (addView()).

我希望可以帮助一些没有写你的code你。

I hope that helps some without writing your code for you.

这篇关于Android的,无需XML布局添加新的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆