Admob 与 Android 中的 simple-xml 集成?

Admob integration with simple-xml in Android?(Admob 与 Android 中的 simple-xml 集成?)
本文介绍了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 集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)