2014-04-30 25 views
0

我在Google和stackoverflow上搜索過,我瀏覽了所有的問題和答案,似乎沒有任何東西適用於我。該廣告仍然顯示在底部我的活動.. 有誰知道我做錯了什麼?不能讓admobs廣告在底部顯示

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

**** ERROR未知類型爲0x0(glSizeof,72)

glUtilsParamSize:不明PARAM 0x00000b44

glUtilsParamSize:不明PARAM 0x00000bd0

**** ERROR未知類型爲0x0(glSizeof,72)

glUtilsParamSize:不明PARAM 0x00000b44

glUtilsParamSize:不明PARAM 0x00000bd0

**** ERROR未知類型爲0x0(glSizeof,72)

回答

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阿恩添加到佈局

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

當我這樣做,廣告仍然顯示在頂部:/ – Jonas

+0

不,它應該工作,確保android:layout_height =「wrap_content」 – Libin

+0

也嘗試設置一些高度adview,如果需要 – Libin

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

如果我這樣做,廣告根本不會顯示:/ – Jonas

+0

這是行不通的。他需要將橫幅放在底部,並在頂部放置其他視圖。 – Libin

0

你的代碼是好的,但你需要的ListView的機器人:上方=」 @ + id/ad「

+0

當我這樣做時,我的應用崩潰了 – Jonas