缺少必需的XML属性"adSize"

Glo*_*ork 17 android admob

当我启动应用程序时,我得到"必需的XML属性"adSize"缺失".这是写在我的智能手机屏幕而不是我的横幅.

我尝试了基于堆栈的不同解决方案(xmlns:ads="http://schemas.android.com/apk/res-auto"而不是代替xmlns:ads="http://schemas.android.com/apk/libs/com.google.ads"或代替xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"),但它不起作用.

这是我的java代码(一个简单的Hello World,只是为了尝试实现一个横幅):

package com.example.publicite;

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

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}
Run Code Online (Sandbox Code Playgroud)

这是我的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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/libs/com.google.ads"
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="MyAdUnitId"
    ads:loadAdOnCreate="true"
    ads:testDevices="TEST_EMULATOR" />

<Button
    android:id="@+id/votrescore"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="..." />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.publicite"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="13"
    android:targetSdkVersion="13" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version"/>

    <activity
        android:name="com.example.publicite.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

 </manifest>
Run Code Online (Sandbox Code Playgroud)

我使用谷歌播放服务库.

nKn*_*nKn 31

尝试以这种方式更改声明:

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adUnitId="YOUR_AD_UNIT_ID"
    ads:adSize="BANNER"/>
Run Code Online (Sandbox Code Playgroud)

----编辑----

您也可以尝试以编程方式执行此操作.简单地说,代替AdView布局项,定义a LinearLayout和by代码执行以下操作:

final AdView adView = new AdView(getActivity());
adView.setAdUnitId("YourId");
adView.setAdSize(AdSize.BANNER);

final LinearLayout adLinLay = (LinearLayout) view.findViewById(R.id.your_defined_linearlayout);
adLinLay.addView(adView);

final AdRequest.Builder adReq = new AdRequest.Builder();
final AdRequest adRequest = adReq.build();
adView.loadAd(adRequest);
Run Code Online (Sandbox Code Playgroud)


ziz*_*utg 8

这是一个奇怪的答案.我刚刚重启了我的日食,它盯着工作.这可能对某人有所帮助.

只需重启eclipse或android studio即可


ket*_*tom 7

我有同样的问题。

对我的解决方案:

 xmlns:ads=""
Run Code Online (Sandbox Code Playgroud)

变成

xmlns:ads="http://schemas.android.com/apk/res-auto"
Run Code Online (Sandbox Code Playgroud)


kar*_*g01 7

通过更改名称空间 uri 为我解决了问题

 xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
Run Code Online (Sandbox Code Playgroud)

xmlns:ads="http://schemas.android.com/apk/res-auto"
Run Code Online (Sandbox Code Playgroud)


jos*_*uin 5

我遇到了同样的问题,并使用xmlns标签进行了更正。我放置了两个“ xmlns:ads”标签(一个用于AdView中的“ res-auto”标签,另一个用于父级布局中的“工具”标签)。我必须对“ res auto”使用两个标签,一个用于FloatingActionButton中的xmlns:app,另一个用于AdView中的xmlns:ads:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.v7.widget.Toolbar
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/fragment_start_margin"
        android:background="@drawable/fondo_proyectos"
        android:elevation="4dp"
        android:gravity="bottom"
        android:minHeight="@dimen/toolbar_height">
    </android.support.v7.widget.Toolbar>

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/av_bottom_banner"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_inferior_ad_unit_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        />

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/av_bottom_banner"
        android:fitsSystemWindows="true">

        <android.support.design.widget.FloatingActionButton
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/av_bottom_banner"
            android:layout_alignParentEnd="true"
            android:layout_gravity="bottom|end"
            android:layout_marginLeft="@dimen/fab_margin"
            android:layout_marginRight="@dimen/fab_margin"
            android:elevation="4dp"
            android:src="@android:drawable/ic_input_add"
            android:tint="@android:color/white"
            app:fabSize="normal"
            app:srcCompat="@drawable/ic_account_circle" />

        <include layout="@layout/proyecto_content" />

    </android.support.design.widget.CoordinatorLayout>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)