0

アプリでの admob 広告の配置に問題があります。以下のコードでは、次のエラーが表示されます error parsing XML: unbound prefix

私はそれを修正することはできません。私は何を間違っていますか?広告を配置する別の方法はありますか?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"    
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <com.admob.android.ads.AdView
   android:id="@+id/ads"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   myapp:backgroundColor="#000000"
   myapp:primaryTextColor="#FFFFFF"
   myapp:secondaryTextColor="#CCCCCC"
   myapp:refreshInterval="10"
   android:visibility="visible" />
</LinearLayout>
4

2 に答える 2

2

コンパイラはあなたのmyapp:

admobsdk:代わりに使用してください。

コード例を参照してください。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:admobsdk="http://schemas.android.com/apk/res/joke.content"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ImageView android:id="@+id/photo" android:src="@drawable/joker"
                android:layout_width="wrap_content" android:layout_height="wrap_content" />
        <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">
                <TextView android:id="@+id/title" android:text=""
                        android:layout_width="wrap_content" android:layout_height="wrap_content"
                        android:textSize="24sp" android:textColor="@color/css_a"
                        android:layout_centerInParent="true" android:layout_alignParentTop="true"></TextView>
        </RelativeLayout>
        <ScrollView android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:layout_weight="1">
                <TextView android:layout_width="fill_parent"
                        android:layout_height="wrap_content" android:text="" android:id="@+id/content"
                        android:textSize="18sp" />
        </ScrollView>

        <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="fill_parent">
                <Button android:text="下一篇" android:id="@+id/next"
                        android:layout_width="wrap_content" android:layout_height="wrap_content"
                        android:layout_alignParentRight="true" android:layout_marginRight="15dip"
                        android:textSize="22sp"></Button>
        </RelativeLayout>
        <com.admob.android.ads.AdView android:id="@+id/ad"
                android:layout_width="fill_parent" admobsdk:backgroundColor="#000000"
                admobsdk:textColor="#FFFFFF" admobsdk:refreshInterval="60"
                admobsdk:keywords="笑话" android:layout_height="wrap_content"
                admobsdk:testing="false" admobsdk:isGoneWithoutAd="false" />
</LinearLayout>

前のコードに次の行があることを確認してください。

xmlns:admobsdk="http://schemas.android.com/apk/res/joke.content"

attrs.xml (res/values フォルダー内) ファイルは次のようになっていますか?

<?xml version="1.0" encoding="utf-8" ?> 
    <resources>
      <declare-styleable name="com.admob.android.ads.AdView">
        <attr name="backgroundColor" format="color" /> 
        <attr name="primaryTextColor" format="color" /> 
        <attr name="secondaryTextColor" format="color" /> 
        <attr name="keywords" format="string" /> 
        <attr name="refreshInterval" format="integer" /> 
      </declare-styleable>
    </resources>

そうでない場合は、res/values フォルダーに attrs.xml という名前の xml ファイルを作成し、このコードをそこにコピーします。

joke.contentあなたのパッケージ名です。パッケージ名に変更することを忘れないでください。

于 2012-05-10T17:43:10.250 に答える
2

LinearLayout で次の行を見逃しました: xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

次の URL をご覧ください。

https://developers.google.com/mobile-ads-sdk/docs/android/banner_xml

于 2012-05-10T17:51:50.480 に答える