Android 布局中的多个 Adview

发布于 2024-11-30 23:55:31 字数 863 浏览 3 评论 0原文

我必须在布局中制作两个 AdView。布局的顶部和底部。我已经做了一个(顶部)。现在我想在布局的底部再添加一个 AdView。如何实现?提前致谢。我的布局中顶部 AdView 的代码如下。

@SuppressWarnings({ "deprecation", "unused" })
public class BannerEssentials extends Activity{
WebView webview;
static String MY_BANNER_UNIT_ID="google";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// BANNER 1

// Lookup R.layout.main
AbsoluteLayout layout = (AbsoluteLayout)findViewById(R.id.linearLayout);

// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
AdView adView = new AdView(this, AdSize.BANNER, MY_BANNER_UNIT_ID);

// Add the adView to it
layout.addView(adView);

// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);

adView.loadAd(request)

I have to make of two AdViews in a layout. Both top and Bottom of a layout. I have done for one(the top). Now i want to make it one more AdView in the bottom of the layout. How to achieve it? Thanks in advance. My Code for top AdView in layout as follows.

@SuppressWarnings({ "deprecation", "unused" })
public class BannerEssentials extends Activity{
WebView webview;
static String MY_BANNER_UNIT_ID="google";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// BANNER 1

// Lookup R.layout.main
AbsoluteLayout layout = (AbsoluteLayout)findViewById(R.id.linearLayout);

// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
AdView adView = new AdView(this, AdSize.BANNER, MY_BANNER_UNIT_ID);

// Add the adView to it
layout.addView(adView);

// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);

adView.loadAd(request)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

醉生梦死 2024-12-07 23:55:31

将另一个项目添加到线性布局,宽度=“fill_parent”,高度=“0dip”。然后设置权重=“1”。这应该具有将下面的任何东西推下去的效果。然后复制上面的代码以添加到新广告中。

您应该考虑在 XML 中定义视图,广告也可以直接通过 XML 插入,或者您也可以 定义您自己的自定义视图

Add another item to the linearlayout with width="fill_parent" and height="0dip". Then set the weight="1". This should have the effect of pushing whatever is below down. Then duplicate the code above to add in the new advertisement.

You should look into defining your views in XML, advertisements can also be inserted directly through XML or you could also define your own custom view

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