由于我在我的横幅广告应用程序中迁移到Google Play服务,因此即使没有加载广告,它也会占用空白。
我不希望横幅在未加载时占用空格。
我的XML代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="vertical"
tools:context=".MainActivity" >
<GridView
android:id="@+id/icon_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="4" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-ABC/ABC" />
</RelativeLayout>
答案 0 :(得分:4)
将您的adView的展示次数隐藏为android:visibility="gone"
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-ABC/ABC"
android:visibility="gone" />
并将setAdListener
中的广告观看次数视为
adView.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
}
@Override
public void onAdFailedToLoad(int error) {
adView.setVisibility(View.GONE);
}
@Override
public void onAdLeftApplication() {
}
@Override
public void onAdOpened() {
}
@Override
public void onAdLoaded() {
adView.setVisibility(View.VISIBLE);
}
});
答案 1 :(得分:1)
隐藏您添加到GONE的可见性,并在加载后使其可见。
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-ABC/ABC"
android:visibility="gone" />
当你想让它可见时,就是在加载广告之前:
adviewName.setVisibility(View.VISIBLE);