Admob 与 Android 中的 simple-xml 集成? [英] Admob integration with simple-xml in Android?

查看:29
本文介绍了Admob 与 Android 中的 simple-xml 集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难将 Admob 横幅集成到我的游戏中.我使用了 simple-xml-2.6.2.jar 库,因为我认为它很容易在我的游戏中实现.现在我有一个布局文件,其中包含发布者 ID 和测试设备的正确代码:

I am having a hard time integrating an Admob banner into my game. I have used simple-xml-2.6.2.jar library because I considered it to be simple to implement into my game. Now I have a single layout file, with the correct code for publisher ID and test device:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
<com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="xxxxxxxxxxx"
                     ads:adSize="BANNER"
                     ads:testDevices="TEST_EMULATOR, zzzzzzzzzzzz"
                     ads:loadAdOnCreate="true"/>
</LinearLayout>

游戏在横向模式下运行,我希望您将广告显示为顶部或底部的横幅,但没有显示任何测试广告,我没有任何想法这是为什么.任何帮助都将不胜感激!

The game runs in landscape mode, and I would like tu get the ads to show as a banner at the top or bottom, but there aren't any test ads being shown, and I haven't got any ideas as to why is that. Any help is apreciated!

推荐答案

在 xml 中使用下面的代码说 xml 名称是 adview.xml

Use below code in xml say xml name is adview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/adView"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="50dip"/>

现在在您的 Activity 中加载广告.

Now in your Activity load the ad.

 AdView adView = new AdView(this,AdSize.BANNER,"yourid");
 LinearLayout ll= (LinearLayout) findViewById(R.id.adView);
 ll.addView(adView);
 AdRequest ar = new AdRequest();
 ar.setGender(AdRequest.FEMALE);
 adView.loadAd(ar);

您可以像这样在您的任何 xml 活动中包含此视图(xml).

You can include this view(xml) in any of your activity from xml like this..

 <include layout="@layout/adview" />  // your xml

这篇关于Admob 与 Android 中的 simple-xml 集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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