簡體   English   中英

Android App中的Admob廣告問題

[英]Issues with Admob Ads in Android App

我在使用xml嵌入廣告時遇到問題。 我嘗試使用xml進行此操作,但它告訴我錯誤: 解析XML時出錯: com.google.ads.AdView上的未綁定偏好設置:

執行此操作后未顯示,但我在logCat上看到了傳入的廣告。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/activity_tuto_layout">



<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:background="@drawable/card_shadow_base"
    android:layout_marginTop="@dimen/default_vertical_margin"
    android:layout_marginLeft="@dimen/default_horizontal_margin"
    android:layout_marginRight="@dimen/default_horizontal_margin"
    android:paddingBottom="2dp"
    android:id="@+id/tuto_title_card">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/ic_launcher"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="false"
        android:layout_alignParentTop="true" />

    <TextSwitcher
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tuto_text_switcher"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/imageView">

    </TextSwitcher>


</RelativeLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tuto_title_card"
    android:layout_above="@+id/closeButton" />
<LinearLayout        
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:layout_above="@id/closeButton"
    android:layout_below="@+id/pager">

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
     ads:adUnitId="xxxxxxxxxxxxx" />
</LinearLayout>

<Button
    android:id="@+id/closeButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:background="@drawable/button_close"
    android:paddingBottom="12dp"
    android:paddingTop="12dp"
    android:text="@string/tuto_button_close"
    android:textColor="@color/white"
    android:textSize="@dimen/home_text_size" />

在我的java文件中:

    AdView adView = (AdView)findViewById(R.id.adView);
    AdRequest aRequest = new AdRequest();
    aRequest.setTesting(true);
            aRequest.addTestDevice("C0150396075730E422F8D1C212A5B658");
    adView.loadAd(aRequest); 

我在這里做錯了什么?

您需要在第一個RelativeLayout中添加名稱空間xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

更改第一個RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/activity_tuto_layout">

有:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/activity_tuto_layout">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM