无法将NativeExpressAdView可见性设置为GONE

时间:2016-09-12 09:54:34

标签: java android

如果我这么简单:

            nativeAd = (NativeExpressAdView) mActivity.findViewById(R.id.adView);
            nativeAd.loadAd(new AdRequest.Builder().build());

我看到了原生广告。但是,如果我添加nativeAd.setVisibility(LinearLayout.GONE);并在按下按钮后执行nativeAd.setVisibility(LinearLayout.VISIBLE);,我会在LogCat中收到两个警告:

            Received error HTTP response code: 403
            There was a problem getting an ad response. ErrorCode: 0

我做错了什么?只有当用户点击另一个活动中的按钮时,我才会将添加内容显示在同一屏幕上。

2 个答案:

答案 0 :(得分:0)

如果它对任何人感兴趣 - 只需将原生广告放在布局中,并使布局为GONE。

答案 1 :(得分:0)

将NativeExpressAdView放在LinearLayout中,例如:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/llad"
android:visibility="invisible"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<com.google.android.gms.ads.NativeExpressAdView
    android:id="@+id/ad_View"
    android:layout_gravity="center|top"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adUnitId="ca-app-pub-your_id"
    ads:adSize="FULL_WIDTHx80">
</com.google.android.gms.ads.NativeExpressAdView>
 </LinearLayout>
课堂上的

        View view = LayoutInflater.from(context).inflate(R.layout.adese, parent, false);
        final NativeExpressAdView adView = (NativeExpressAdView) view.findViewById(R.id.ad_View);
        final LinearLayout lld = (LinearLayout)view.findViewById(R.id.llad);
        adView.setVisibility(View.GONE);
        lld.setVisibility(View.GONE);
        AdRequest request = new AdRequest.Builder()
                .addTestDevice("your_device_number")
                .build();
        adView.loadAd(request);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                super.onAdLoaded();
                adView.setVisibility(View.VISIBLE);
                lld.setVisibility(View.VISIBLE);
            }
        });

以这种方式对我有用!