开发者

How to get AdMob ads to show up at the top of my screen?

I've got AdMob working in my app, but it's showing up at the bottom of my screen. Does anyone know how to force it to the top of the screen? I don't want to use RelativeLayout as I already have a bunch of stuff set up with my LinearLayout.

I'm initiating AdMob via an @id reference in my main.xml and some calls in the java activity:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
         android:id="@+id/linearLayout"   .....this is t开发者_如何学Gohe only line I added for my Admob reference
         android:orientation="vertical"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         >

    <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center">

    <ImageView android:id="@+id/ImageView01"
        android:src="@drawable/image01"
        android:layout_height="150dp"
        android:layout_width="200dp"
        android:scaleType="centerCrop"
        android:paddingTop="10px">
    </ImageView>

    </LinearLayout>
           ....

Then I have this in my java activity...

    setContentView(R.layout.main);

    //create an adView
    LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
    String pubID = "a14d9cfd23d60cf";
    AdView adView = new AdView(this, AdSize.BANNER, pubID);
    layout.addView(adView);
    AdRequest request = new AdRequest();

    //request.setTesting(true);
    adView.loadAd(request);

EDIT.....SOLUTION.......

Never mind...I got it figured out. It's all about where you place the layout id. If I move android:id="@+id/linearLayout" down into the LinearLayout just below the one it's in now, My ad shows at the top.


One way of going about this is by placing the ad view in your XML. What you do is put it just like any other view in the top of your view hierarchy under the root LinearLayout. In other words, you will have something like:

<LinearLayout
android:id="@+id/linearLayout"   .....this is the only line I added for my Admob reference
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="MY_AD_UNIT_ID"
                         ads:adSize="BANNER"/>
    <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center">

    <ImageView android:id="@+id/ImageView01"
        android:src="@drawable/image01"
        android:layout_height="150dp"
        android:layout_width="200dp"
        android:scaleType="centerCrop"
        android:paddingTop="10px">
    </ImageView>

    </LinearLayout>

Take a look at http://code.google.com/mobile/ads/docs/android/banner_xml.html for more info on this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜