修正了PrefereceActivity底部的广告

时间:2014-01-05 12:06:55

标签: android admob preferenceactivity

我有LiveWallpaper的PreferenceActivity,并使用此处的解决方案(LINK)来制作Admob广告。它有效,但广告在用户向上或向下滚动时会消失,并在用户进入视图时再次加载。有没有办法让广告始终保持在活动的底部(或顶部)(比如常规活动)?

1 个答案:

答案 0 :(得分: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());