Domanda

I've searched on Google and stackoverflow, I browsed all the questions and answers and nothing seems to work for me.. The ad is still showing up at the bottom of my activity.. Does anyone know what i am doing wrong?

public class MainActivity extends Activity {
String[] myItems;
RelativeLayout RelLay;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);

    RelLay = (RelativeLayout) findViewById (R.id.RelLay);
    AdView ad = (AdView) findViewById(R.id.ad);

    AdView adView = new AdView(this.getApplicationContext());

        adView = new AdView(this);
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.setAdUnitId("ca-app-pub-5045823047142424/5834743995");
        RelLay.addView(adView, 0);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);


    populateListView();
    registerClickCallBack();

}

my xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/RelLay"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
 <ListView
    android:id="@+id/listView"
    android:layout_width="wrap_content"
    android:layout_height="400dp"
    android:layout_alignParentTop="true" >
</ListView>

<com.google.android.gms.ads.AdView
    android:id="@+id/ad"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    ads:adSize="SMART_BANNER"
    android:layout_below="@id/listView"
    ads:adUnitId="ca-app-pub-5045823047142424/5834743995" 
    android:layout_weight="1"/>
</RelativeLayout>

and when it shows up at the top of the activity i get an error like this:

04-30 16:17:57.787: E/eglCodecCommon(1468):

**** ERROR unknown type 0x0 (glSizeof,72)

glUtilsParamSize: unknow param 0x00000b44

glUtilsParamSize: unknow param 0x00000bd0

**** ERROR unknown type 0x0 (glSizeof,72)

glUtilsParamSize: unknow param 0x00000b44

glUtilsParamSize: unknow param 0x00000bd0

**** ERROR unknown type 0x0 (glSizeof,72)

È stato utile?

Soluzione

Create a parent vertical LinearLayout and place your ListView with layout weight as 2 and AdView weight as 1. This will make sure ListView will be at top and adjust its height based on AdView . So that AdView will be shown always at bottom.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">

<ListView
    android:id="@+id/listView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@color/Red"
    android:layout_weight="2"/>

<com.google.android.gms.ads.AdView
    android:id="@+id/welcomeAdView"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    ads:adSize="SMART_BANNER"
    ads:adUnitId=""
    android:layout_weight="1"/>
</LinearLayout>

Also, change you code to just load the ad, Don't add the AdView agin to the layout

   AdView ad = (AdView) findViewById(R.id.ad);
   AdRequest adRequest = new AdRequest.Builder().build();
   ad.loadAd(adRequest);

Altri suggerimenti

use simple xml banner no need of java

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        xmlns:tools="http://schemas.android.com/tools"

        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <com.google.ads.AdView
            android:id="@+id/ad"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="your publisher id here"
            ads:loadAdOnCreate="true" />


    </RelativeLayout>

Your code is fine, but you need the ListView android:above="@+id/ad"

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top