2014-01-05 45 views
0

我有一個LiveWallpaper的PreferenceActivity,並使用此處的解決方案(LINK)創建Admob廣告。它可以工作,但當用戶向上或向下滾動並在視圖中再次加載時,廣告會消失。有沒有辦法讓廣告始終停留在活動的底部(或頂部)(就像常規活動一樣)?PrefereceActivity底部的固定廣告

+0

請提供XML佈局。 –

+0

XML在鏈接中。 – domen

回答

0

之前

((LinearLayout)view).addView(adView); 

嘗試設置layoutParam像

adView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)) 

或更改像以下佈局:

<?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/mainLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/ad_unit_id"/> 
</RelativeLayout> 

和代碼的一部分會是這樣的:

mAdView = (AdView) findViewById(R.id.adView); 
    mAdView.setAdListener(new ToastAdListener(this)); 
    mAdView.loadAd(new AdRequest.Builder().build());