gpt4 book ai didi

android - Google Play 服务缺少必需的 XML 属性 "adSize"

转载 作者:搜寻专家 更新时间:2023-11-01 08:51:29 24 4
gpt4 key购买 nike

我查看了所有其他问题,但没有找到我的答案我得到了这个代码

<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="@drawable/sfondo"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ds:testDevices="TEST_EMULATOR,C8D15E364178"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>

但它说“缺少必需的 XML 属性“adSize””我也尝试从 Activity 中创建横幅,但没有任何改变

最佳答案

“loadAdOnCreate”和“testDevices”XML 属性不再可用。使您的广告与 Google Play 服务配合使用

这是 XML 布局

<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="INSERT_YOUR_AD_UNIT_ID_HERE"/>
</LinearLayout>

这是你的java文件

package com.google.example.gms.ads.xml;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import android.app.Activity;
import android.os.Bundle;

/**
* A simple {@link Activity} which embeds an AdView in its layout XML.
*/
public class BannerXMLSample extends Activity {

private static final String TEST_DEVICE_ID = "INSERT_YOUR_TEST_DEVICE_ID_HERE";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// The "loadAdOnCreate" and "testDevices" XML attributes no longer available.
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice(TEST_DEVICE_ID)
.build();
adView.loadAd(adRequest);
}
}

引用这里的例子 https://github.com/googleads/googleads-mobile-android-examples/tree/master/admob/banner-xml

关于android - Google Play 服务缺少必需的 XML 属性 "adSize",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22948395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com