首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在安卓游戏的表面视图上集成AdMob横幅广告

在安卓游戏的表面视图上集成AdMob横幅广告
EN

Stack Overflow用户
提问于 2018-06-19 09:22:16
回答 2查看 369关注 0票数 2

我正在开发一个android游戏。上下文视图扩展了曲面视图类。我正在尝试在屏幕底部放置一个横幅。我已经使用this guide设置了谷歌AdMob软件开发工具包。我已经将AdView添加到布局中,并使用another guide加载了一个测试广告。

这是我的MainActivity.java:

代码语言:javascript
复制
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(new GameView(this));

        MobileAds.initialize(this, "ca-app-pub-1042328490971088~5397056328");

        AdView adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");

        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);
    }
}

当我运行这段代码时,当我的游戏继续正常运行时,根本没有显示任何广告。我的想法是,也许广告就在那里,但看不见,因为游戏视图占据了整个屏幕。如果有人能帮助我确保我的横幅广告被覆盖在画布上或画布被缩小以适应广告,我将不胜感激。

下面是我的AndroidManifest.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.haakamaujla.myfirstgame">

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="Stunty Skys"
        android:roundIcon="@drawable/icon"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity" android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

下面是我的activity_main.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout     xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50919419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档