google Adview Android - 如何在 xml 中设置禁用

google Adview in Android - how to set disabled in xml

我有一种情况,我想禁用 Adview 并更喜欢 xml。 adview 本身在我的布局文件中看起来像这样:

  <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-12345678934343/85666666">

我怎样才能禁用它?一种方法是将它包裹在线性布局周围,然后隐藏该布局,但我也想禁用实际的网络调用,那么 adview 中是否有一个我可以使用的属性等?它必须在 xml 之前完成,因为我将合并数据绑定来打开和关闭广告。

How can i disable this ?

只要不调用加载广告的方法就相当于禁用了。不会显示任何广告。

one way is to wrap it around a linearlayout and then hide that layout but i want to disable the actual network call too, so is there a attribute in adview i can use etc ?

这只是一个观点。可见性、宽度、高度、重力等常见属性也适用于此。

Its necessary to do it by xml because im going to incorporate data binding to turn the ad on and off.

不,没有 XML 也可以。只需在您的 Java 代码中创建广告视图并将其附加到您的布局。同样你也可以把它拆下来。