Admob没有覆盖Android游戏

时间:2014-02-15 02:52:29

标签: android admob

我知道这应该很容易,但我仍在学习,我不确定如何让AdMob横幅显示在顶部(拉伸宽度以填满屏幕)而不会覆盖游戏。这是在没有任何XML文件的情况下编写的,下面是我所拥有的代码,它只是在屏幕顶部显示覆盖游戏的广告。

提前感谢你们提供任何帮助。

public class Screen extends Activity implements Runnable, OnTouchListener, SensorEventListener {
private SurfaceHolder holder;
private boolean locker = true, initialised = false;
private Thread thread;
//public WakeLock WL;
private int width = 0, height = 0;
public float cameraX = 0, cameraY = 0;

public Activity activity = this;
public boolean debug_mode = false;
private long now = SystemClock.elapsedRealtime(), lastRefresh, lastfps;
public SurfaceView surface;
private int fps = 0, frames = 0, runtime = 0, drawtime = 0;

//sensor
SensorManager sm;
Sensor s;
float sensorx, calibratex = 0;
float sensory, calibratey = 0;
private boolean default_lanscape = false;
private int default_lanscape_rotation = 0;

//world origin
public final int TOP_LEFT = 0, BOTTOM_LEFT = 1;
public int origin = TOP_LEFT;

//layout
public RelativeLayout layout;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    activity = this;

    //full screen
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    //create surface
    layout = new RelativeLayout(this);
    surface = new SurfaceView(this);
    setContentView(layout);
    layout.addView(surface);

    AdView ad = new AdView(this, AdSize.BANNER, "XXXXXXXX");
    //layout
    layout.addView(ad);
    AdRequest request = new AdRequest();
    AdRequest adRequest = new AdRequest(); 
    adRequest.addTestDevice("xxxxxxxxxxxxxxxxx");
    ad.loadAd(request);

    holder = surface.getHolder();

    //listeners
    surface.setOnTouchListener(this);

    // start game loop
    thread = new Thread(this);
    thread.start();

    onCreate();

}

1 个答案:

答案 0 :(得分:0)

您真的需要阅读并了解Android布局或您将无法理解所提供的任何帮助。 http://developer.android.com/guide/topics/ui/declaring-layout.html

话虽如此,首先用LinearLayout替换RelativeLayout。我强烈建议您使用XML布局。你不太可能迷路,特别是因为你不熟悉这一点。