问题
Okay I made a lot of research before I came here (sorry for my english).
My problem is : I made an application and I implement Admob 4.3.1 (my application is developped on Android 3.2 (with eclipse).
First time I was having the error "You must have INTERNET and ACCESS_NETWORK_STATE permission, I put them on my AndroidManifest.xml, now all is okay but when I start my application, my ads are not showing up.
I hope you can help me soon... thank you very much.
Here is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.package.sound"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/gg"
android:label="@string/app_name" >
<activity
android:name=".testpackagesound"
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=".test1"
android:label="@string/app_name" >
</activity>
<activity
android:name=".test2"
android:label="@string/app_name" >
</activity>
<activity
android:name=".test3"
android:label="@string/app_name">
</activity>
<meta-data android:value="xxxxxxxxxxxx" android:name="ADMOB_PUBLISHER_ID" />
<uses-sdk android:minSdkVersion="7" />
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
Here is my Layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/image"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="test1"
android:textColor="#005113" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="test2"
android:textColor="#970000" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="test3"
android:textColor="#001760" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="50dip" >
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxx"
ads:loadAdOnCreate="true" >
</com.google.ads.AdView>
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true" >
<LinearLayout
android:layout_width="300px"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
>
<Button
android:id="@+id/button4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="test4" />
<Button
android:id="@+id/button18"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="test18" />
</LinearLayout>
</ScrollView>
</LinearLayout>
回答1:
So basically the only thing I can think of is that you missed something in your layout.xml file. Here's some example that might help you:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
//............Some other views
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
ads:adUnitId="Your Add ID"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
//Some other views
If I'm not wrong you either forgot line 3 or you don't have a correct add id. Hope this helps you.
If this doesn't help you take a look over the official android addmob documentation or maybe here.
Also I hope you imported your AddMob libray to your project.
回答2:
Ads will not display if there is not enough room to in the layout. Check the logcat log for any and all ad related messages. See this Admob ads not showing - Android for suggestions if this is the case.
来源:https://stackoverflow.com/questions/9077400/admob-ads-is-not-showing-up