无法获得广告以显示在底部

时间:2014-04-30 20:25:17

标签: java android xml admob

我已经在Google和stackoverflow上搜索了,我浏览了所有的问题和答案,似乎没有什么对我有用..广告仍然出现在我的活动底部.. 有谁知道我做错了什么?

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();

}

我的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>

当它出现在活动的顶部时,我会收到如下错误:

  

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

     

****错误未知类型0x0(glSizeof,72)

     

glUtilsParamSize:unknow param 0x00000b44

     

glUtilsParamSize:unknow param 0x00000bd0

     

****错误未知类型0x0(glSizeof,72)

     

glUtilsParamSize:unknow param 0x00000b44

     

glUtilsParamSize:unknow param 0x00000bd0

     

****错误未知类型0x0(glSizeof,72)

3 个答案:

答案 0 :(得分:0)

使用简单的xml横幅,不需要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>

答案 1 :(得分:0)

创建父级纵向LinearLayout,并将ListView的布局权重设为2,AdView权重设为1.这将确保ListView位于顶部并进行调整它的高度基于AdView。因此,AdView将始终显示在底部。

 <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>

另外,将代码更改为仅加载广告,不要将AdView agin添加到布局

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

答案 2 :(得分:0)

您的代码很好,但您需要ListView android:above =&#34; @ + id / ad&#34;